[20191216]route妙用.txt

lfree發表於2019-12-17

[20191216]route妙用.txt

--//使用route add -host ip_address reject,可以拒接某臺機器的連線.自己做一個測試:

1.顯示路由表:
# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.100.XXX 0.0.0.0         UG    0      0        0 eth0
169.254.0.0     0.0.0.0         255.255.0.0     U     0      0        0 eth0
192.168.100.0   0.0.0.0         255.255.255.0   U     0      0        0 eth0

2.改寫路由表:
# route add -host 192.168.100.40 reject

3.測試:

# ping 192.168.100.40
connect: Network is unreachable

--//從192.168.100.40操作看看:
# ping 192.168.100.78 -c 2
PING 192.168.100.78 (192.168.100.78) 56(84) bytes of data.
From 192.168.100.40 icmp_seq=0 Destination Host Unreachable
From 192.168.100.40 icmp_seq=1 Destination Host Unreachable

--- 192.168.100.78 ping statistics ---
2 packets transmitted, 0 received, +2 errors, 100% packet loss, time 1001ms
, pipe 2

4.顯示路由表:
# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.100.XXX 0.0.0.0         UG    0      0        0 eth0
169.254.0.0     0.0.0.0         255.255.0.0     U     0      0        0 eth0
192.168.100.0   0.0.0.0         255.255.255.0   U     0      0        0 eth0
192.168.100.40  -               255.255.255.255 !H    0      -        0 -
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
--//這樣就無法ping連線192.168.100.40.

Flags  Possible flags include
U      route is up
H      target is a host
G      use gateway
R      reinstate route for dynamic routing
D      dynamically installed by daemon or redirect
M      modified from routing daemon or redirect
A      installed by addrconf
C      cache entry
!      reject route

5.測試還原:

# route del -host 192.168.100.40 reject
# ping 192.168.100.40 -c 2
PING 192.168.100.40 (192.168.100.40) 56(84) bytes of data.
64 bytes from 192.168.100.40: icmp_seq=1 ttl=64 time=0.109 ms
64 bytes from 192.168.100.40: icmp_seq=2 ttl=64 time=0.137 ms

--- 192.168.100.40 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1000ms
rtt min/avg/max/mdev = 0.109/0.123/0.137/0.014 ms

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/267265/viewspace-2668955/,如需轉載,請註明出處,否則將追究法律責任。

相關文章