server和desktop都需要配置,本文档只记录server配置
[root@server0 ~]# systemctl stop firewalld.service ////停止firewalld防火墙服务
[root@server0 ~]# systemctl disable firewalld.service ////关闭firewalld防火墙服务
rm '/etc/systemd/system/basic.target.wants/firewalld.service'
rm '/etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service'
[root@server0 ~]# systemctl mask firewalld.service ////隐藏firewalld防火墙服务
ln -s '/dev/null' '/etc/systemd/system/firewalld.service'
[root@server0 ~]# systemctl enable iptables.service ////启动iptables防火墙服务(开机自启)
ln -s '/usr/lib/systemd/system/iptables.service' '/etc/systemd/system/basic.target.wants/iptables.service'
[root@server0 ~]# systemctl start iptables.service ////开启iptables防火墙服务
[root@server0 ~]# iptables -F ////清空iptables防火墙策略
[root@server0 ~]# iptables -A INPUT -s 172.25.1.0/24 -j REJECT ///增加入方向拒绝策略,-A策略方向,-s地址列表,-j策略名称
[root@server0 ~]# iptables -L ////查看iptables防火墙策略
Chain INPUT (policy ACCEPT)
target prot opt source destination
REJECT all -- 172.25.1.0/24 anywhere reject-with icmp-port-unreachable
Chain FORWARD (policy ACCEPT)
target prot opt source destination
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
[root@server0 ~]# service iptables save ////保存策略配置
iptables: Saving firewall rules to /etc/sysconfig/iptables:[ OK ]
[root@server0 ~]# systemctl restart iptables.service ////重启iptables防火墙服务
[root@server0 ~]# systemctl status iptables.service ////查询运行状态
iptables.service - IPv4 firewall with iptables
Loaded: loaded (/usr/lib/systemd/system/iptables.service; enabled)
Active: active (exited) since Tue 2018-04-24 10:03:04 CST; 10min ago
Process: 3957 ExecStop=/usr/libexec/iptables/iptables.init stop (code=exited, status=0/SUCCESS)
Process: 4007 ExecStart=/usr/libexec/iptables/iptables.init start (code=exited, status=0/SUCCESS)
Main PID: 4007 (code=exited, status=0/SUCCESS)
Apr 24 10:03:04 server0.example.com systemd[1]: Starting IPv4 firewall with iptables...
Apr 24 10:03:04 server0.example.com iptables.init[4007]: iptables: Applying firewall rules: [ OK ]
Apr 24 10:03:04 server0.example.com systemd[1]: Started IPv4 firewall with iptables.
[root@server0 ~]#