防火墙指定IPport
firewall-cmd --remove-port=29093/tcp --permanent
firewall-cmd --remove-port=80/tcp --permanent
firewall-cmd --reload
firewall-cmd --list-all
firewall-cmd --permanent --zone=public --add-rich-rule='rule family="ipv4" source address="27.196.95.59" port protocol="tcp" port="20022" accept'
firewall-cmd --permanent --zone=public --add-rich-rule='rule family="ipv4" source address="172.16.140.22" port protocol="tcp" port="33306" accept'
firewall-cmd --permanent --zone=public --add-rich-rule='rule family="ipv4" source address="27.196.95.50" port protocol="tcp" port="29093" accept'
firewall-cmd --permanent --zone=public --remove-rich-rule='rule family="ipv4" source address="172.16.140.65" port protocol="tcp" port="33306" accept'
iptables防火墙
- 有时候关了防火墙,下次登录又开了,发现服务起不来,找半天才发现防火墙又开了,所以建议永久关闭防火墙和selinux
- 基本操作
service iptables status
service iptables stop
service iptables start
service iptables restart
chkconfig iptables off
chkconfig iptables on
- 开启80端口
vim /etc/sysconfig/iptables
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
service iptables restart
firewall防火墙
systemctl status firewalld
firewall-cmd --state
systemctl stop firewalld
systemctl disable firewalld
service firewalld start
service firewalld restart
service firewalld stop
firewall-cmd --list-all
- #查询、开放、关闭端口
firewall-cmd --query-port=8080/tcp
firewall-cmd --permanent --add-port=80/tcp
firewall-cmd --permanent --remove-port=8080/tcp
firewall-cmd --reload
centos7版本对防火墙进行加强,不再使用原来的iptables,启用firewalld
systemctl start firewalld
systemctl status firewalld
systemctl disable firewalld
systemctl stop firewalld
systemctl enable firewalld.service
systemctl disable firewalld.service
systemctl is-enabled firewalld.service
systemctl list-unit-files|grep enabled
systemctl --failed
firewall-cmd --version
firewall-cmd --help
firewall-cmd --state
firewall-cmd --zone=public --list-ports
firewall-cmd --reload
firewall-cmd --get-zone-of-interface=eth0
firewall-cmd --panic-on
firewall-cmd --panic-off
firewall-cmd --query-panic
开启一个端口
firewall-cmd --zone=public(作用域) --add-port=80/tcp(端口和访问类型) --permanent(永久生效)
firewall-cmd --zone=public --add-service=http --permanent
firewall-cmd --reload
firewall-cmd --zone= public --query-port=80/tcp
firewall-cmd --zone= public --remove-port=80/tcp --permanent
firewall-cmd --list-services
firewall-cmd --get-services
firewall-cmd --add-service=<service>
firewall-cmd --delete-service=<service>
firewall-cmd --zone=public --query-port=80/tcp
firewall-cmd --zone=public --query-port=8080/tcp
firewall-cmd --zone=public --query-port=3306/tcp
firewall-cmd --zone=public --add-port=8080/tcp --permanent
firewall-cmd --zone=public --add-port=3306/tcp --permanent
firewall-cmd --zone=public --query-port=3306/tcp
firewall-cmd --zone=public --query-port=8080/tcp
firewall-cmd --reload
firewall-cmd --zone=public --query-port=3306/tcp
firewall-cmd --zone=public --query-port=8080/tcp
参数解释
–add-service
–zone
–add-port=80/tcp
–permanent
详细使用
firewall-cmd --permanent --zone=public --add-rich-rule='rule family="ipv4" source address="192.168.0.4/24" service name="http" accept' //设置某个ip访问某个服务
firewall-cmd --permanent --zone=public --remove-rich-rule='rule family="ipv4" source address="192.168.0.4/24" service name="http" accept' //删除配置
firewall-cmd --permanent --add-rich-rule 'rule family=ipv4 source address=192.168.0.1/2 port port=80 protocol=tcp accept' //设置某个ip访问某个端口
firewall-cmd --permanent --remove-rich-rule 'rule family=ipv4 source address=192.168.0.1/2 port port=80 protocol=tcp accept' //删除配置
firewall-cmd --query-masquerade
firewall-cmd --add-masquerade
firewall-cmd --remove-masquerade
firewall-cmd --add-forward-port=port=80:proto=tcp:toport=8080
firewall-cmd --add-forward-port=proto=80:proto=tcp:toaddr=192.168.1.0.1
firewall-cmd --add-forward-port=proto=80:proto=tcp:toaddr=192.168.0.1:toport=8080
centos7以下版本
/sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT
/sbin/iptables -I INPUT -p tcp --dport 22 -j ACCEPT
/sbin/iptables -I INPUT -p tcp --dport 8080 -j ACCEPT
/etc/rc.d/init.d/iptables save
/etc/init.d/iptables status
1) 永久性生效,重启后不会复原
开启: chkconfig iptables on
关闭: chkconfig iptables off
2) 即时生效,重启后复原
开启: service iptables start
关闭: service iptables stop