CentOS7中執行
service iptables start/stop
會報錯Failed to start iptables.service: Unit iptables.service failed to load: No such file or directory.
在CentOS 7或RHEL 7或Fedora中防火牆由firewalld來管理,
如果要添加范圍例外端口 如 1000-2000
語法命令如下:啟用區域端口和協議組合
firewall-cmd [--zone=<zone>] --add-port=<port>[-<port>]/<protocol> [--timeout=<seconds>]
此舉將啟用端口和協議的組合。端口可以是一個單獨的端口 <port> 或者是一個端口范圍 <port>-<port> 。協議可以是 tcp 或 udp。
實際命令如下:
firewall-cmd --permanent --add-port=1000-2000/tcp
執行可以成功
用該命令查詢firewall-cmd --permanent --query-port=1000/tcp
當然你可以還原傳統的管理方式。
執行一下命令:
systemctl stop firewalld systemctl mask firewalld
並且安裝iptables-services:
yum install iptables-services
設置開機啟動:
systemctl enable iptables
systemctl stop iptables systemctl start iptables systemctl restart iptables systemctl reload iptables
保存設置:
service iptables save
OK,再試一下應該就好使了
開放某個端口 在/etc/sysconfig/iptables里添加
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 8080 -j ACCEPT