# centos7 firewall指定IP与端口访问(常用)
1、启动,关闭,重启防火墙
```shell
systemctl start firewalld.service
systemctl restart firewalld.service
```
```shell
firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="IP名" port protocol="tcp" port="端口号" accept"
firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="192.168.2.0/24" port protocol="tcp" port="5432" accept"
firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="192.168.142.166" port protocol="tcp" port="30000-31000" accept"
firewall-cmd --permanent --remove-rich-rule="rule family="ipv4" source address="192.168.142.166" port protocol="tcp" port="11300" accept"
```
```shell
firewall-cmd --list-all
```
```shell
firewall-cmd --reload
```
```shell
firewall-cmd --permant --add-rich="rule family="ipv4" source address="192.168.2.0/24" port protocol="tcp" port="5432" accept"
firewall-cmd --reload
```