linux和windows路由条目添加方法。

Windows下添加静态路由


1、添加一条路由表
route add 60.232.142.25 mask 255.255.255.248 192.168.100.250 metric 3 if 2
临时添加一条静态路由记录,重启机器失效,所有到60.232.142.25/29网段的数据包,都通过2号网络接口卡走192.168.100.250的网关,优先级为3。

route add �Cp 60.232.142.25 mask 255.255.255.248 192.168.100.250 metric 3 if 2
作用同上,添加 一条永久静态路由,不会因为重启机器而丢失,-p选项表示保存.

2、删除一条路由表
route delete 60.232.142.25
route delete 60.232.*
请留心:如果有两条路由记录有着相同的“目的网络号”,则会将两条记录同时删除。如果只想删除其中某一条的话,请在删除后用route add命令再添加上其中一条。

3、修改一条路由记录
route change 157.0.0.0 mask 255.0.0.0 157.55.80.254 metric 2 if 2
change参数只能修改“网关”和“跳数”


---------------------
linux下添加路由的方法:

一:使用 route 命令添加使用route 命令添加的路由,机器重启或者网卡重启后路由就失效了。
//添加到主机的路由
# route add �Chost 192.168.168.110 dev eth0
# route add �Chost 192.168.168.119 gw 192.168.168.1

//添加到网络的路由
# route add �Cnet IP netmask MASK eth0
# route add �Cnet IP netmask MASK gw IP
# route add �Cnet IP/24 eth1

# route add -net 192.168.9.253 netmask 255.255.255.255 gw 192.168.31.254

//添加默认网关
# route add default gw IP

//删除路由
# route del �Chost 192.168.168.110 dev eth0

# route del -net 192.168.9.253 netmask 255.255.255.255 gw 192.168.31.254

参数解释:

add 增加路由
del 删除路由
-net 设置到某个网段的路由
-host 设置到某台主机的路由
gw 出口网关 IP地址
dev 出口网关 物理设备名


二:在linux下设置永久路由的方法:
1.在/etc/rc.local里添加方法:
route add -net 192.168.3.0/24 dev eth0
route add -net 192.168.2.0/24 gw 192.168.3.254
route add -net 192.168.34.0/24 gw 192.168.31.254

2.在/etc/sysconfig/network里添加到末尾
方法:GATEWAY=gw-ip 或者 GATEWAY=gw-dev

3./etc/sysconfig/network-script/route-eth0:

   如没有route-eth0则创建名为route- eth0的文件
   vim /etc/sysconfig/network-script/route-eth0
  在此文件添加如下格式的内容
  192.168.1.0/24 via 192.168.0.1

   via 网关出口 IP地址
   dev 网关出口 物理设备名


路由的添加对于我们来说很重要,有的时候网络不通,也许就是你路由没加。

服务器ip(eth0)
[root@localhost net]# ifconfig
eth0 Link encap:Ethernet HWaddr 00:0C:29:E3:9A:15
inet addr:172.16.2.205 Bcast:172.16.2.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fee3:9a15/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:4776 errors:0 dropped:0 overruns:0 frame:0
TX packets:3348 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:439384 (429.0 KiB) TX bytes:390425 (381.2 KiB)
Interrupt:11 Base address:0x1400

lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:254 errors:0 dropped:0 overruns:0 frame:0
TX packets:254 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:22128 (21.6 KiB) TX bytes:22128 (21.6 KiB)

查看原始路由、网关信息
[root@localhost net]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
172.16.2.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
169.254.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth0


[root@centos6 ~]# netstat -rn
Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
192.168.16.0    0.0.0.0         255.255.240.0      U           0        0        eth0
0.0.0.0         192.168.30.10   0.0.0.0              UG           0        0        eth0

==============================================

添加默认网关
[root@localhost net]# route add default gw 172.16.2.50
[root@localhost net]# route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
172.16.2.0 * 255.255.255.0 U 0 0 0 eth0
169.254.0.0 * 255.255.0.0 U 0 0 0 eth0
default 172.16.2.50 0.0.0.0 UG 0 0 0 eth0
==============================================

添加一个ip(eth0:1)
[root@localhost net]# ifconfig eth0:1 192.168.168.119 netmask 255.255.255.0 up
[root@localhost net]# ifconfig
eth0 Link encap:Ethernet HWaddr 00:0C:29:E3:9A:15
inet addr:172.16.2.205 Bcast:172.16.2.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fee3:9a15/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:5071 errors:0 dropped:0 overruns:0 frame:0
TX packets:3569 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:466532 (455.5 KiB) TX bytes:416538 (406.7 KiB)
Interrupt:11 Base address:0x1400

eth0:1 Link encap:Ethernet HWaddr 00:0C:29:E3:9A:15
inet addr:192.168.168.119 Bcast:192.168.168.255 Mask:255.255.255.0

UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
Interrupt:11 Base address:0x1400

在查看路由信息
[root@localhost net]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
172.16.2.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
192.168.168.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
169.254.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth0
0.0.0.0 172.16.2.50 0.0.0.0 UG 0 0 0 eth0
==================================

添加一条到主机192.168.168.110的路由(通过eth0:1)
[root@localhost net]# route add -host 192.168.168.110 dev eth0:1
[root@localhost net]# route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.168.110 * 255.255.255.255 UH 0 0 0 eth0
172.16.2.0 * 255.255.255.0 U 0 0 0 eth0
192.168.168.0 * 255.255.255.0 U 0 0 0 eth0
169.254.0.0 * 255.255.0.0 U 0 0 0 eth0
default 172.16.2.50 0.0.0.0 UG 0 0 0 eth0
==================================

添加一条到主机192.168.168.120的路由(通过ip192.168.168.119)
[root@localhost net]# route add -host 192.168.168.120 gw 192.168.168.119
[root@localhost net]# route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.168.120 192.168.168.119 255.255.255.255 UGH 0 0 0 eth0
192.168.168.110 *

你可能感兴趣的:(Linux添加静态路由)