Linux作業系統靜態路由設定技巧介紹

2022-03-24 08:08:34 字數 1729 閱讀 1639

現在有五個裝置,pc1接rout1,rout1再接rout2,rout2再接rout3,rout3再接pc2,拓撲圖見下:

□————○————○————○————□

pc1 rout1 rout2 rout3 pc2

pc1 192.168.1.88/24

rout1 192.168.1.128/24 192.168.2.128/24

rout2 192.168.2.66/24 192.168.3.66/24

rout3 192.168.3.100/24 192.168.4.33/24

pc2 192.168.4.66/24

pc1配置如下:

#ifconfig eth0 192.168.1.88 netmask 255.255.255.0

#route add default gw 192.168.1.128

rout1配置如下:

#ifconfig eth0 192.168.1.128 netmask 255.255.255.0

#ifconfig eth0: 1 192.168.2.128 netmask 255.255.255.0

#route add -net 192.168.4.0/24 gw 192.168.2.66

rout2配置如下:

#ifconfig eth0 192.168.2.66 netmask 255.255.255.0

#ifconfig eth0: 1 192.168.3.66 netmask 255.255.255.0

#route add -net 192.168.1.0/24 gw 192.168.2.128

#route add -net 192.168.4.0/24 gw 192.168.3.100

rout3配置如下:

#ifconfig eth0 192.168.3.100 netmask 255.255.255.0

#ifconfig eth0: 1 192.168.4.33 netmask 255.255.255.0

#route add -net 192.168.1.0/24 gw 192.168.3.66

pc2配置如下:

#ifconfig eth0 192.168.4.66 netmask 255.255.255.0

#route add default gw 192.168.4.33

這樣pc1就能ping通pc2了。

注:上面三個路由器這裡用三颱pc代替。用電腦代替路由器,必須要啟用電腦的ip**功能,改/proc/sys/net/ipv4/ip_forward裡的內容為1(預設為0),用下面的命令完成

#e cho 1 > /proc/sys/net/ipv4/ip_forward

網路重啟後,上面的檔案自動改為0

補充幾個命令:

1、刪除預設路由

#route del default

2、檢視路由

#route -n

3、設定指定網段路由

#route add -net 192.168.3.0 netmask 255.255.255.0 gw 192.168.6.66

或者#route add -net 192.168.3.0/24 gw 192.168.6.66

4、刪除指定網段路由

#route del -net 192.168.3.0 netmask 255.255.255.0

或者#route del -net 192.168.3.0/24

Windows作業系統新增永久靜態路由

1.比如 新增一條去往 10.10.10.0 24網段的靜態路由,指定去往此網段的路由都走 172.20.153.254閘道器 route p add 10.10.10.0 mask 255.255.255.0 172.20.153.254 其中此處用到的幾個引數的作用是 p 表示永久路由,重啟後不...

linux靜態IP 靜態路由設定

1.修改 etc sysconfig network config檔案 networkmanager yes 通過 networkmanage 的使用者方法設定 networkmanager no 通過 ipfu傳統的方法設定 選擇這個 2.修改 etc sysconfig network ifcf...

linux靜態IP 靜態路由設定

1.修改 etc sysconfig network config檔案 networkmanager yes 通過 networkmanage 的使用者方法設定 networkmanager no 通過 ipfu傳統的方法設定 選擇這個 2.修改 etc sysconfig network ifcf...