首页 >> 技术文章 >> 详细内容
windows和linux服务器手动添加路由条目的方法

在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 –p 60.232.142.25 mask 255.255.255.248 192.168.100.250 metric 3 if 2
作用同上,只是这是一条长久路由,不会因为重启机器而丢失。

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 –host 192.168.168.110 dev eth0
# route add –host 192.168.168.119 gw 192.168.168.1

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

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

//删除路由
# route del –host 192.168.168.110 dev eth0
route add -net 192.168.9.253 netmask 255.255.255.255 gw 192.168.31.254

在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/static-router :
any net x.x.x.x/24 gw y.y.y.y

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

服务器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@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

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:258 errors:0 dropped:0 overruns:0 frame:0
TX packets:258 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:22480 (21.9 KiB) TX bytes:22480 (21.9 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
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 *

南京服务器托管 | 南京服务器租用 | 南京主机托管 | 南京主机租用 | 南京华昊数据 | www.467.cn |
TEL:400-025-9-467  025-58633651 QQ:23190019

发布者:admin 发布时间:2014/2/19 阅读:3421

Baidu
Copyright © 2002-2021 467.Cn All rights reserved    南京华昊网络技术有限公司    版权所有
备案序号:苏ICP备13052121号    ISP经营许可证:苏B2-20080166    ICP/SP经营许可证:苏B2-20130350      苏公网安备 32011102010099号
地址:南京市江北新区大桥北路77号电信大楼5楼    电话:025-58633651(8线)  13913852884  传真:025-58497310    E-mail:467cn@163.com    邮编:210032
网址:Www.467.Cn    QQ在线支持:点击这里给我发消息 点击这里给我发消息