臨時路由
使用 route 命令添加
使用route 命令添加的路由仰猖,機(jī)器重啟或者網(wǎng)卡重啟后路由就失效了,方法:
添加到主機(jī)的路由
# route add –host 192.168.1.11 dev eth0
# route add –host 192.168.1.12 gw 192.168.1.1
添加到網(wǎng)絡(luò)的路由
# route add –net 192.168.1.11 netmask 255.255.255.0 eth0
# route add –net 192.168.1.11 netmask 255.255.255.0 gw 192.168.1.1
# route add –net 192.168.1.0/24 eth1
添加默認(rèn)網(wǎng)關(guān)
# route add default gw 192.168.2.1
刪除路由
# route del –host 192.168.1.11 dev eth0
route -n 查看到的路由信息
#route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
169.254.0.0 0.0.0.0 255.255.0.0 U 1002 0 0 eth0
192.168.0.0 10.138.255.247 255.255.0.0 UG 0 0 0 eth0
10.138.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth0
172.16.0.0 10.138.255.247 255.240.0.0 UG 0 0 0 eth0
100.64.0.0 10.138.255.247 255.192.0.0 UG 0 0 0 eth0
10.0.0.0 10.138.255.247 255.0.0.0 UG 0 0 0 eth0
42.0.0.0 10.138.255.247 255.0.0.0 UG 0 0 0 eth0
11.0.0.0 10.138.255.247 255.0.0.0 UG 0 0 0 eth0
30.0.0.0 10.138.255.247 255.0.0.0 UG 0 0 0 eth0
170.0.0.0 10.138.255.247 255.0.0.0 UG 0 0 0 eth0
0.0.0.0 10.138.255.247 0.0.0.0 UG 0 0 0 eth0
## genmask 就是-net gateway 就是gw
永久路由
- 在/etc/rc/local中添加
# route add -net 192.168.3.0/24 dev eth0
# route add -net 192.168.2.0/24 gw 192.168.2.254
- 在/etc/sysconfig/network里添加到末尾
方法:GATEWAY=gw-ip 或者 GATEWAY=gw-dev - /etc/sysconfig/static-routes : (沒有static-routes的話就手動建立一個這樣的文件)
any net 192.168.3.0/24 gw 192.168.3.254
any net 10.250.228.128 netmask 255.255.255.192 gw 10.250.228.129
- 開啟 IP 轉(zhuǎn)發(fā):
# echo "1" >/proc/sys/net/ipv4/ip_forward (臨時)
# vi /etc/sysctl.conf --> net.ipv4.ip_forward=1 (永久開啟)