首页 > 代码库 > 模拟断网线
模拟断网线
Last login: Fri Jan 16 03:53:09 2015 from 192.168.5.120
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]# clear
[root@localhost ~]# iptables --list
Chain INPUT (policy ACCEPT)
target prot opt source destination
Chain FORWARD (policy ACCEPT)
target prot opt source destination
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
[root@localhost ~]# ping 192.168.5.120
PING 192.168.5.120 (192.168.5.120) 56(84) bytes of data.
64 bytes from 192.168.5.120: icmp_seq=1 ttl=64 time=0.267 ms
64 bytes from 192.168.5.120: icmp_seq=2 ttl=64 time=0.333 ms
64 bytes from 192.168.5.120: icmp_seq=3 ttl=64 time=0.265 ms
^C
--- 192.168.5.120 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2259ms
rtt min/avg/max/mdev = 0.265/0.288/0.333/0.034 ms
禁用ip
注:参数-I是表示Insert(添加),-D表示Delete(删除)。后面跟的是规则,INPUT表示入站,***.***.***.***表示要封停的IP,DROP表示放弃连接 通过-s指定来源地址进行限制。
[root@localhost ~]# iptables -I INPUT -s 192.168.5.120 -j DROP
[root@localhost ~]# iptables --list
Chain INPUT (policy ACCEPT)
target prot opt source destination
DROP all -- 192.168.5.120 anywhere
Chain FORWARD (policy ACCEPT)
target prot opt source destination
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
[root@localhost ~]# ping 192.168.5.120
PING 192.168.5.120 (192.168.5.120) 56(84) bytes of data.
^C
--- 192.168.5.120 ping statistics ---
115 packets transmitted, 0 received, 100% packet loss, time 114008ms
恢复ip
[root@localhost ~]# iptables -D INPUT -s 192.168.5.120 -j DROP
[root@localhost ~]# iptables --list
Chain INPUT (policy ACCEPT)
target prot opt source destination
Chain FORWARD (policy ACCEPT)
target prot opt source destination
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
[root@localhost ~]# ping 192.168.5.120
PING 192.168.5.120 (192.168.5.120) 56(84) bytes of data.
64 bytes from 192.168.5.120: icmp_seq=1 ttl=64 time=0.288 ms
64 bytes from 192.168.5.120: icmp_seq=2 ttl=64 time=0.276 ms
64 bytes from 192.168.5.120: icmp_seq=3 ttl=64 time=0.256 ms
^C
--- 192.168.5.120 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2389ms
rtt min/avg/max/mdev = 0.256/0.273/0.288/0.018 ms
[root@localhost ~]#
模拟断网线