防火墙filter表的出站、入站访问控制
1)在网关gw1上限制ping测试(允许ping别人,禁止别人ping自己)
丢弃进来的ping请求包、允许进来的各种ping应答包(非请求包)
[root@gw1 ~]# iptables -A INPUT -p icmp --icmp-type echo-request -j DROP
[root@gw1 ~]# iptables -A INPUT -p icmp ! --icmp-type echo-request -j ACCEPT
或者,允许出去的ping请求包、丢弃出去的各种ping应答包(非请求包)
[root@gw1 ~]# iptables -A OUTPUT -p icmp --icmp-type echo-request -j ACCEPT
[root@gw1 ~]# iptables -A OUTPUT -p icmp ! --icmp-type echo-request -j DROP
2)验证ping限制效果
在网关gw1上ping主机pc120,可以ping通:
[root@gw1 ~]# ping -c4 -W2 174.16.16.120
PING 174.16.16.120 (174.16.16.120) 56(84) bytes of data.
64 bytes from 174.16.16.120: icmp_seq=1 ttl=64 time=2.32 ms
64 bytes from 174.16.16.120: icmp_seq=2 ttl=64 time=0.226 ms
64 bytes from 174.16.16.120: icmp_seq=3 ttl=64 time=0.583 ms
64 bytes from 174.16.16.120: icmp_seq=4 ttl=64 time=0.239 ms
--- 174.16.16.120 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3002ms
rtt min/avg/max/mdev = 0.226/0.844/2.328/0.868 ms
在主机pc205上ping网关gw1,丢包率为100%,实际上被防火墙封堵了:
[root@pc205 ~]# ping -c4 -W2 174.16.16.1
PING 174.16.16.1 (174.16.16.1) 56(84) bytes of data.
--- 174.16.16.1 ping statistics ---
4 packets transmitted, 0 received, 100% packet loss, time 5001ms
[root@pc205 ~]#
3)针对网关gw1上的FTP服务做访问控制
快速安装、启用vsftpd服务:
[root@gw1 ~]# yum -y install vsftpd
.. ..
[root@gw1 ~]# service vsftpd restart
.. ..
禁止从主机pc120访问本机的FTP服务:
[root@gw1 ~]# iptables -A INPUT -s 174.16.16.120 -p tcp --dport 20:21 -j DROP
[root@gw1 ~]# iptables -nL INPUT
Chain INPUT (policy ACCEPT)
target prot opt source destination
DROP icmp -- 0.0.0.0/0 0.0.0.0/0 icmp type 8
ACCEPT icmp -- 0.0.0.0/0 0.0.0.0/0 icmp !type 8
DROP tcp -- 174.16.16.120 0.0.0.0/0 tcp dpts:20:21
4)测试FTP访问控制效果
在被封堵的主机pc120上,访问gw1的FTP服务将会失败:
[root@pc205 ~]# ftp 174.16.16.1
ftp: connect: 连接超时
ftp> quit
[root@pc205 ~]#
在其他主机(比如svr5)上,可以正常访问gw1的FTP服务:
[root@svr5 ~]# ftp 174.16.16.1
Connected to 174.16.16.1 (174.16.16.1).
220 (vsFTPd 2.2.2)
Name (174.16.16.1:root): ftp
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> quit
221 Goodbye.
[root@svr5 ~]#