- 浏览: 305977 次
- 性别:
- 来自: 大连
-
文章分类
最新评论
-
syw19901001:
从入门到精通,不错。http://www.ihref.com/ ...
使用git进行版本控制 -
轻指飞扬:
...
一场程序员和老板的对话 -
luogen33:
ttttttttttttttttttttttttttttttt ...
lsmod -
luogen33:
ttttttttttttttttttt
lsmod -
vaqeteart:
嗯那
得到与享受
route [-CFvnee]
route [-v] [-A family] add [-net|-host] target [netmask Nm] [gw Gw] [metric N] [mss M] [window W] [irtt I] [reject] [mod] [dyn] [reinstate] [[dev] If]
route [-v] [-A family] del [-net|-host] target [gw Gw] [netmask Nm] [metric N] [[dev] If]
route [-V] [--version] [-h] [--help]
[功能]
设定和操作路由器表。
[描述]
route用来操作管理内核的IP路由表。它的作用是在使用ifconfig命令配置好网络接口之后,通过网络接口设定到特定主机或者网络的静态路由表。
当使用add或者del选项的时候,route修改路由表。如果没有这些选项,那么route会显示当前路由表中的内容。
常用选项:
-n:不使用主机名称而直接使用主机IP或端口号。
-ee:使用详细信息显示。
增加(add)和删除(del)选项的参数:
-net:表示后面所指定的是为一个网络。
-host:表示后面所指定的是一个主机的路由。
netmask:和网络相关,可以设定netmask来决定网络大小。
gw:表示gateway(网关),后面连接其IP。
dev:指定连接的设备(网卡),例如eth0。
[举例]
1、需要预先了解的内容:
(1)路由可为各种品牌路由(例如cisco),PC为访问网络的设备(例如主机)。
(2)路由器上面至少有两类网口,一个可连接WLAN,一个可连接PC组成LAN。
(3)PC只有一个网口,要么连接WLAN,要么连接路由组成LAN。
(4)路由可与PC直连,与之组成LAN;路由也可再与WAN相连,使其LAN内主机可经它访问WAN;也可PC直连到WAN。
(5)内网:又叫LAN,是路由和PC组成的内部局域网,其网内主机假设为172.168.1.*。
(6)外网:又叫WAN,是外部一个更大的局域网,其网内主机假设为10.1.10.*。
(7)PC内网网址(LAN):可静态指定,也可通过路由的dhcp服务动态获取(例如172.168.1.105)。
(8)路由内网网址(LAN):连接到路由的PC以它作为默认网关,PC也可通过它登陆并配置路由(如172.168.1.14)。
(9)PC外网网址(WAN):可静态指定,也可通过WAN网中的dhcp服务动态获取(如10.1.10.182)。(似PC从路由)
(10)路由的外网网址(WAN):可静态指定,也可通过WAN网中的dhcp服务获取(如10.1.10.32)。(似PC从外网)
2、当把路由器插连接WLAN,然后pc连接路由器组成LAN之后:
pc的网址(LAN):172.168.1.105(可以pc自己指定静态的,也可通过路由的dhcp服务动态获取)。
cisco的网址(LAN):172.168.1.14。
pc的网关设置成(LAN):172.168.1.14。
*查看PC机器ip信息:
# ifconfig
eth0 Link encap:Ethernet HWaddr 00:24:7e:03:62:14
inet addr:172.168.1.105 Bcast:172.168.1.255 Mask:255.255.255.0
inet6 addr: fe80::224:7eff:fe03:6214/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:1776511 errors:12 dropped:1 overruns:0 frame:8
TX packets:1174511 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:934065225 (934.0 MB) TX bytes:107898203 (107.8 MB)
Interrupt:16 Memory:fc500000-fc520000
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:310438 errors:0 dropped:0 overruns:0 frame:0
TX packets:310438 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:28063379 (28.0 MB) TX bytes:28063379 (28.0 MB)
*查看当前路由如下:
# route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
default 172.168.1.14 0.0.0.0 UG 0 0 0 eth0
link-local * 255.255.0.0 U 1000 0 0 eth0
172.168.1.0 * 255.255.255.0 U 1 0 0 eth0
可以看到机器路由,其中(其他参见man手册):
Destination:目标网络或者主机。
Gateway:网关地址,如果没有设置则为*。
Genmask:目标网络掩码;如果目标主机则用"255.255.255.255",如果默认路由则用"0.0.0.0"。
Flags标志说明:
U Up表示此路由当前为启动状态
H Host,表示此网关为一主机
G Gateway,表示此网关为一路由器
R Reinstate Route,使用动态路由重新初始化的路由
D Dynamically,此路由是动态性地写入
M Modified,此路由是由路由守护程序或导向器动态修改
! 表示此路由当前为关闭状态
Metric:到目标的距离(一般为跳数),当前kernel可能不用,但是路由守护进程可能会需要它。
Ref:此路由引用数目(当前kernel不用)。
Use:对此路由的查找。
Iface:对于这个路由,数据包将要发送到那个接口(网卡)。
*查看路由信息的另外一个方法:
# netstat -rn
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
0.0.0.0 172.168.1.14 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
172.168.1.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
这里,信息类似,速度稍快,不象route需要等待一段时间,(区别是什么?)。然后可以用如下命令查看连通性:
# ping 10.1.10.100
PING 10.1.10.100 (10.1.10.100) 56(84) bytes of data.
From 172.168.1.14 icmp_seq=1 Destination Net Unreachable
From 172.168.1.14 icmp_seq=2 Destination Net Unreachable
可见无法ping通(这里10.1.10.100是外网的一台机器),原因是因为没有给route插入外网网线,而是只将route的lan口与机器相连,当将外网和route的wan口相连之后,就可以ping通了。
# ping 172.168.1.14
PING 172.168.1.14 (172.168.1.14) 56(84) bytes of data.
64 bytes from 172.168.1.14: icmp_req=1 ttl=64 time=0.457 ms
64 bytes from 172.168.1.14: icmp_req=2 ttl=64 time=0.425 ms
可见可以ping通本网段(这里172.168.1.14是路由器)。
3、让pc直接连接到外部网络,不经过路由器:
pc的网址:10.1.10.182。
外网其网内主机ip是10.1.10.*。
*查看PC基本信息:
# ifconfig
eth0 Link encap:Ethernet HWaddr 00:24:7e:03:62:14
inet addr:10.1.10.182 Bcast:10.1.10.255 Mask:255.255.255.0
inet6 addr: fe80::224:7eff:fe03:6214/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:1776739 errors:12 dropped:2 overruns:0 frame:8
TX packets:1174650 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:934090706 (934.0 MB) TX bytes:107913085 (107.9 MB)
Interrupt:16 Memory:fc500000-fc520000
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:310442 errors:0 dropped:0 overruns:0 frame:0
TX packets:310442 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:28063715 (28.0 MB) TX bytes:28063715 (28.0 MB)
*查看PC路由信息:
# route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
default ns.amazon.esdl. 0.0.0.0 UG 0 0 0 eth0
10.1.10.0 * 255.255.255.0 U 1 0 0 eth0
link-local * 255.255.0.0 U 1000 0 0 eth0
# netstat -rn
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
0.0.0.0 10.1.10.254 0.0.0.0 UG 0 0 0 eth0
10.1.10.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
在这个路由信息的基础上,测试连通性:
# ping 10.1.10.119
PING 10.1.10.119 (10.1.10.119) 56(84) bytes of data.
64 bytes from 10.1.10.119: icmp_req=1 ttl=64 time=3.72 ms
这里,10.1.10.119是网内另外一台主机。
*添加一个192.168.1.0网络:
# route add -net 192.168.1.0 netmask 255.255.255.0 dev eth0
# route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
default ns.amazon.esdl. 0.0.0.0 UG 0 0 0 eth0
10.1.10.0 * 255.255.255.0 U 1 0 0 eth0
link-local * 255.255.0.0 U 1000 0 0 eth0
192.168.1.0 * 255.255.255.0 U 0 0 0 eth0
*再添加192.0.0.0和192.0.0.0网络:
# route add -net 192.0.0.0 netmask 255.255.0.0 dev eth0
# route add -net 192.0.0.0 netmask 255.0.0.0 dev eth0
# route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
default ns.amazon.esdl. 0.0.0.0 UG 0 0 0 eth0
10.1.10.0 * 255.255.255.0 U 1 0 0 eth0
link-local * 255.255.0.0 U 1000 0 0 eth0
192.0.0.0 * 255.255.255.0 U 0 0 0 eth0
192.0.0.0 * 255.255.0.0 U 0 0 0 eth0
192.168.1.0 * 255.255.255.0 U 0 0 0 eth0
这里,网络地址结合子网掩码来标识。
*删除192.0.0.0:
# route del 192.0.0.0
SIOCDELRT: No such process
# route del -net 192.0.0.0
SIOCDELRT: Invalid argument
# route del -net 192.0.0.0 netmask 255.255.0.0
# route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
default ns.amazon.esdl. 0.0.0.0 UG 0 0 0 eth0
10.1.10.0 * 255.255.255.0 U 1 0 0 eth0
link-local * 255.255.0.0 U 1000 0 0 eth0
192.0.0.0 * 255.255.255.0 U 0 0 0 eth0
192.168.1.0 * 255.255.255.0 U 0 0 0 eth0
# route del -net 192.0.0.0 netmask 255.255.255.0
# route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
default gateway.amazon. 0.0.0.0 UG 0 0 0 eth0
10.1.10.0 * 255.255.255.0 U 1 0 0 eth0
link-local * 255.255.0.0 U 1000 0 0 eth0
192.168.1.0 * 255.255.255.0 U 0 0 0 eth0
从这里可知,如果没有指定子网掩码,那么如果有两个一样的ip的网络就无法删除成功。
*添加一台主机:
# route add -host 10.1.10.47 dev eth0
# route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
default gateway.amazon. 0.0.0.0 UG 0 0 0 eth0
10.1.10.0 * 255.255.255.0 U 1 0 0 eth0
quietheart * 255.255.255.255 UH 0 0 0 eth0
link-local * 255.255.0.0 U 1000 0 0 eth0
192.168.1.0 * 255.255.255.0 U 0 0 0 eth0
# netstat -rn
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
0.0.0.0 10.1.10.254 0.0.0.0 UG 0 0 0 eth0
10.1.10.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
10.1.10.47 0.0.0.0 255.255.255.255 UH 0 0 0 eth0
169.254.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth0
192.168.1.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
# ping 10.1.10.47
PING 10.1.10.47 (10.1.10.47) 56(84) bytes of data.
64 bytes from 10.1.10.47: icmp_req=1 ttl=64 time=8.02 ms
64 bytes from 10.1.10.47: icmp_req=2 ttl=64 time=9.49 ms
从这里我们可以看出,主机10.1.10.47名称是"quietheart",注意,添加主机的时候,不指定netmask。添加之后,仍然可以ping通。
*添加一个默认的网关:
# route add default gw 10.1.10.1
# route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
default 10.1.10.1 0.0.0.0 UG 0 0 0 eth0
default gateway.amazon. 0.0.0.0 UG 0 0 0 eth0
10.1.10.0 * 255.255.255.0 U 1 0 0 eth0
quietheart * 255.255.255.255 UH 0 0 0 eth0
link-local * 255.255.0.0 U 1000 0 0 eth0
192.168.1.0 * 255.255.255.0 U 0 0 0 eth0
这里,默认的路由"default"在没有其他路由匹配的时候,会被使用到,可以有特殊的命令修改默认路由(例如"route add default gw mango-gw"会添加mango-gw主机),具体可以参见"man"手册。
*删除一个默认网关:
# route del default gw 10.1.10.1
# route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
default gateway.amazon. 0.0.0.0 UG 0 0 0 eth0
10.1.10.0 * 255.255.255.0 U 1 0 0 eth0
quietheart * 255.255.255.255 UH 0 0 0 eth0
link-local * 255.255.0.0 U 1000 0 0 eth0
192.168.1.0 * 255.255.255.0 U 0 0 0 eth0
*为一台主机添加一个特定网关:
# route add -host 10.1.10.47 gw 10.1.10.1 dev eth0
# route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
default gateway.amazon. 0.0.0.0 UG 0 0 0 eth0
10.1.10.0 * 255.255.255.0 U 1 0 0 eth0
quietheart 10.1.10.1 255.255.255.255 UGH 0 0 0 eth0
link-local * 255.255.0.0 U 1000 0 0 eth0
192.168.1.0 * 255.255.255.0 U 0 0 0 eth0
这里10.1.10.47的主机名称为quietheart,这里如果gw后面指定的ip地址是不存在的,则命令运行失败,例如:
# route add -host 10.1.10.47 gw 172.168.1.1 dev eth0
SIOCADDRT: No such process
这里,172.168.1.1是不存在的,但是192.168.1.1是存在的,因为路由表中有192.168.1.0的网络,可是实际上192.168.1.1不可达。
*添加一个不可达的路由也无法正常工作,例如:
# route add -host 10.1.10.47 gw 192.168.1.1 dev eth0
# route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
default ns.amazon.esdl. 0.0.0.0 UG 0 0 0 eth0
10.1.10.0 * 255.255.255.0 U 1 0 0 eth0
quietheart 192.168.1.1 255.255.255.255 UGH 0 0 0 eth0
link-local * 255.255.0.0 U 1000 0 0 eth0
192.168.1.0 * 255.255.255.0 U 0 0 0 eth0
# ping 10.1.10.47
PING 10.1.10.47 (10.1.10.47) 56(84) bytes of data.
因为192.168.1.1不可达,所以即使添加上去了,也不能正常工作。
*删除一个主机:
# route del -host 10.1.10.47 dev eth0
# route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
default ns.amazon.esdl. 0.0.0.0 UG 0 0 0 eth0
10.1.10.0 * 255.255.255.0 U 1 0 0 eth0
link-local * 255.255.0.0 U 1000 0 0 eth0
192.168.1.0 * 255.255.255.0 U 0 0 0 eth0
[其它]
有待更新。
参考资料:
http://www.2cto.com/os/201203/125081.html
http://blog.chinaunix.net/uid-22646981-id-3048260.html
man手册
route [-v] [-A family] add [-net|-host] target [netmask Nm] [gw Gw] [metric N] [mss M] [window W] [irtt I] [reject] [mod] [dyn] [reinstate] [[dev] If]
route [-v] [-A family] del [-net|-host] target [gw Gw] [netmask Nm] [metric N] [[dev] If]
route [-V] [--version] [-h] [--help]
[功能]
设定和操作路由器表。
[描述]
route用来操作管理内核的IP路由表。它的作用是在使用ifconfig命令配置好网络接口之后,通过网络接口设定到特定主机或者网络的静态路由表。
当使用add或者del选项的时候,route修改路由表。如果没有这些选项,那么route会显示当前路由表中的内容。
常用选项:
-n:不使用主机名称而直接使用主机IP或端口号。
-ee:使用详细信息显示。
增加(add)和删除(del)选项的参数:
-net:表示后面所指定的是为一个网络。
-host:表示后面所指定的是一个主机的路由。
netmask:和网络相关,可以设定netmask来决定网络大小。
gw:表示gateway(网关),后面连接其IP。
dev:指定连接的设备(网卡),例如eth0。
[举例]
1、需要预先了解的内容:
(1)路由可为各种品牌路由(例如cisco),PC为访问网络的设备(例如主机)。
(2)路由器上面至少有两类网口,一个可连接WLAN,一个可连接PC组成LAN。
(3)PC只有一个网口,要么连接WLAN,要么连接路由组成LAN。
(4)路由可与PC直连,与之组成LAN;路由也可再与WAN相连,使其LAN内主机可经它访问WAN;也可PC直连到WAN。
(5)内网:又叫LAN,是路由和PC组成的内部局域网,其网内主机假设为172.168.1.*。
(6)外网:又叫WAN,是外部一个更大的局域网,其网内主机假设为10.1.10.*。
(7)PC内网网址(LAN):可静态指定,也可通过路由的dhcp服务动态获取(例如172.168.1.105)。
(8)路由内网网址(LAN):连接到路由的PC以它作为默认网关,PC也可通过它登陆并配置路由(如172.168.1.14)。
(9)PC外网网址(WAN):可静态指定,也可通过WAN网中的dhcp服务动态获取(如10.1.10.182)。(似PC从路由)
(10)路由的外网网址(WAN):可静态指定,也可通过WAN网中的dhcp服务获取(如10.1.10.32)。(似PC从外网)
2、当把路由器插连接WLAN,然后pc连接路由器组成LAN之后:
pc的网址(LAN):172.168.1.105(可以pc自己指定静态的,也可通过路由的dhcp服务动态获取)。
cisco的网址(LAN):172.168.1.14。
pc的网关设置成(LAN):172.168.1.14。
*查看PC机器ip信息:
# ifconfig
eth0 Link encap:Ethernet HWaddr 00:24:7e:03:62:14
inet addr:172.168.1.105 Bcast:172.168.1.255 Mask:255.255.255.0
inet6 addr: fe80::224:7eff:fe03:6214/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:1776511 errors:12 dropped:1 overruns:0 frame:8
TX packets:1174511 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:934065225 (934.0 MB) TX bytes:107898203 (107.8 MB)
Interrupt:16 Memory:fc500000-fc520000
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:310438 errors:0 dropped:0 overruns:0 frame:0
TX packets:310438 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:28063379 (28.0 MB) TX bytes:28063379 (28.0 MB)
*查看当前路由如下:
# route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
default 172.168.1.14 0.0.0.0 UG 0 0 0 eth0
link-local * 255.255.0.0 U 1000 0 0 eth0
172.168.1.0 * 255.255.255.0 U 1 0 0 eth0
可以看到机器路由,其中(其他参见man手册):
Destination:目标网络或者主机。
Gateway:网关地址,如果没有设置则为*。
Genmask:目标网络掩码;如果目标主机则用"255.255.255.255",如果默认路由则用"0.0.0.0"。
Flags标志说明:
U Up表示此路由当前为启动状态
H Host,表示此网关为一主机
G Gateway,表示此网关为一路由器
R Reinstate Route,使用动态路由重新初始化的路由
D Dynamically,此路由是动态性地写入
M Modified,此路由是由路由守护程序或导向器动态修改
! 表示此路由当前为关闭状态
Metric:到目标的距离(一般为跳数),当前kernel可能不用,但是路由守护进程可能会需要它。
Ref:此路由引用数目(当前kernel不用)。
Use:对此路由的查找。
Iface:对于这个路由,数据包将要发送到那个接口(网卡)。
*查看路由信息的另外一个方法:
# netstat -rn
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
0.0.0.0 172.168.1.14 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
172.168.1.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
这里,信息类似,速度稍快,不象route需要等待一段时间,(区别是什么?)。然后可以用如下命令查看连通性:
# ping 10.1.10.100
PING 10.1.10.100 (10.1.10.100) 56(84) bytes of data.
From 172.168.1.14 icmp_seq=1 Destination Net Unreachable
From 172.168.1.14 icmp_seq=2 Destination Net Unreachable
可见无法ping通(这里10.1.10.100是外网的一台机器),原因是因为没有给route插入外网网线,而是只将route的lan口与机器相连,当将外网和route的wan口相连之后,就可以ping通了。
# ping 172.168.1.14
PING 172.168.1.14 (172.168.1.14) 56(84) bytes of data.
64 bytes from 172.168.1.14: icmp_req=1 ttl=64 time=0.457 ms
64 bytes from 172.168.1.14: icmp_req=2 ttl=64 time=0.425 ms
可见可以ping通本网段(这里172.168.1.14是路由器)。
3、让pc直接连接到外部网络,不经过路由器:
pc的网址:10.1.10.182。
外网其网内主机ip是10.1.10.*。
*查看PC基本信息:
# ifconfig
eth0 Link encap:Ethernet HWaddr 00:24:7e:03:62:14
inet addr:10.1.10.182 Bcast:10.1.10.255 Mask:255.255.255.0
inet6 addr: fe80::224:7eff:fe03:6214/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:1776739 errors:12 dropped:2 overruns:0 frame:8
TX packets:1174650 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:934090706 (934.0 MB) TX bytes:107913085 (107.9 MB)
Interrupt:16 Memory:fc500000-fc520000
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:310442 errors:0 dropped:0 overruns:0 frame:0
TX packets:310442 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:28063715 (28.0 MB) TX bytes:28063715 (28.0 MB)
*查看PC路由信息:
# route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
default ns.amazon.esdl. 0.0.0.0 UG 0 0 0 eth0
10.1.10.0 * 255.255.255.0 U 1 0 0 eth0
link-local * 255.255.0.0 U 1000 0 0 eth0
# netstat -rn
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
0.0.0.0 10.1.10.254 0.0.0.0 UG 0 0 0 eth0
10.1.10.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
在这个路由信息的基础上,测试连通性:
# ping 10.1.10.119
PING 10.1.10.119 (10.1.10.119) 56(84) bytes of data.
64 bytes from 10.1.10.119: icmp_req=1 ttl=64 time=3.72 ms
这里,10.1.10.119是网内另外一台主机。
*添加一个192.168.1.0网络:
# route add -net 192.168.1.0 netmask 255.255.255.0 dev eth0
# route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
default ns.amazon.esdl. 0.0.0.0 UG 0 0 0 eth0
10.1.10.0 * 255.255.255.0 U 1 0 0 eth0
link-local * 255.255.0.0 U 1000 0 0 eth0
192.168.1.0 * 255.255.255.0 U 0 0 0 eth0
*再添加192.0.0.0和192.0.0.0网络:
# route add -net 192.0.0.0 netmask 255.255.0.0 dev eth0
# route add -net 192.0.0.0 netmask 255.0.0.0 dev eth0
# route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
default ns.amazon.esdl. 0.0.0.0 UG 0 0 0 eth0
10.1.10.0 * 255.255.255.0 U 1 0 0 eth0
link-local * 255.255.0.0 U 1000 0 0 eth0
192.0.0.0 * 255.255.255.0 U 0 0 0 eth0
192.0.0.0 * 255.255.0.0 U 0 0 0 eth0
192.168.1.0 * 255.255.255.0 U 0 0 0 eth0
这里,网络地址结合子网掩码来标识。
*删除192.0.0.0:
# route del 192.0.0.0
SIOCDELRT: No such process
# route del -net 192.0.0.0
SIOCDELRT: Invalid argument
# route del -net 192.0.0.0 netmask 255.255.0.0
# route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
default ns.amazon.esdl. 0.0.0.0 UG 0 0 0 eth0
10.1.10.0 * 255.255.255.0 U 1 0 0 eth0
link-local * 255.255.0.0 U 1000 0 0 eth0
192.0.0.0 * 255.255.255.0 U 0 0 0 eth0
192.168.1.0 * 255.255.255.0 U 0 0 0 eth0
# route del -net 192.0.0.0 netmask 255.255.255.0
# route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
default gateway.amazon. 0.0.0.0 UG 0 0 0 eth0
10.1.10.0 * 255.255.255.0 U 1 0 0 eth0
link-local * 255.255.0.0 U 1000 0 0 eth0
192.168.1.0 * 255.255.255.0 U 0 0 0 eth0
从这里可知,如果没有指定子网掩码,那么如果有两个一样的ip的网络就无法删除成功。
*添加一台主机:
# route add -host 10.1.10.47 dev eth0
# route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
default gateway.amazon. 0.0.0.0 UG 0 0 0 eth0
10.1.10.0 * 255.255.255.0 U 1 0 0 eth0
quietheart * 255.255.255.255 UH 0 0 0 eth0
link-local * 255.255.0.0 U 1000 0 0 eth0
192.168.1.0 * 255.255.255.0 U 0 0 0 eth0
# netstat -rn
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
0.0.0.0 10.1.10.254 0.0.0.0 UG 0 0 0 eth0
10.1.10.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
10.1.10.47 0.0.0.0 255.255.255.255 UH 0 0 0 eth0
169.254.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth0
192.168.1.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
# ping 10.1.10.47
PING 10.1.10.47 (10.1.10.47) 56(84) bytes of data.
64 bytes from 10.1.10.47: icmp_req=1 ttl=64 time=8.02 ms
64 bytes from 10.1.10.47: icmp_req=2 ttl=64 time=9.49 ms
从这里我们可以看出,主机10.1.10.47名称是"quietheart",注意,添加主机的时候,不指定netmask。添加之后,仍然可以ping通。
*添加一个默认的网关:
# route add default gw 10.1.10.1
# route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
default 10.1.10.1 0.0.0.0 UG 0 0 0 eth0
default gateway.amazon. 0.0.0.0 UG 0 0 0 eth0
10.1.10.0 * 255.255.255.0 U 1 0 0 eth0
quietheart * 255.255.255.255 UH 0 0 0 eth0
link-local * 255.255.0.0 U 1000 0 0 eth0
192.168.1.0 * 255.255.255.0 U 0 0 0 eth0
这里,默认的路由"default"在没有其他路由匹配的时候,会被使用到,可以有特殊的命令修改默认路由(例如"route add default gw mango-gw"会添加mango-gw主机),具体可以参见"man"手册。
*删除一个默认网关:
# route del default gw 10.1.10.1
# route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
default gateway.amazon. 0.0.0.0 UG 0 0 0 eth0
10.1.10.0 * 255.255.255.0 U 1 0 0 eth0
quietheart * 255.255.255.255 UH 0 0 0 eth0
link-local * 255.255.0.0 U 1000 0 0 eth0
192.168.1.0 * 255.255.255.0 U 0 0 0 eth0
*为一台主机添加一个特定网关:
# route add -host 10.1.10.47 gw 10.1.10.1 dev eth0
# route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
default gateway.amazon. 0.0.0.0 UG 0 0 0 eth0
10.1.10.0 * 255.255.255.0 U 1 0 0 eth0
quietheart 10.1.10.1 255.255.255.255 UGH 0 0 0 eth0
link-local * 255.255.0.0 U 1000 0 0 eth0
192.168.1.0 * 255.255.255.0 U 0 0 0 eth0
这里10.1.10.47的主机名称为quietheart,这里如果gw后面指定的ip地址是不存在的,则命令运行失败,例如:
# route add -host 10.1.10.47 gw 172.168.1.1 dev eth0
SIOCADDRT: No such process
这里,172.168.1.1是不存在的,但是192.168.1.1是存在的,因为路由表中有192.168.1.0的网络,可是实际上192.168.1.1不可达。
*添加一个不可达的路由也无法正常工作,例如:
# route add -host 10.1.10.47 gw 192.168.1.1 dev eth0
# route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
default ns.amazon.esdl. 0.0.0.0 UG 0 0 0 eth0
10.1.10.0 * 255.255.255.0 U 1 0 0 eth0
quietheart 192.168.1.1 255.255.255.255 UGH 0 0 0 eth0
link-local * 255.255.0.0 U 1000 0 0 eth0
192.168.1.0 * 255.255.255.0 U 0 0 0 eth0
# ping 10.1.10.47
PING 10.1.10.47 (10.1.10.47) 56(84) bytes of data.
因为192.168.1.1不可达,所以即使添加上去了,也不能正常工作。
*删除一个主机:
# route del -host 10.1.10.47 dev eth0
# route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
default ns.amazon.esdl. 0.0.0.0 UG 0 0 0 eth0
10.1.10.0 * 255.255.255.0 U 1 0 0 eth0
link-local * 255.255.0.0 U 1000 0 0 eth0
192.168.1.0 * 255.255.255.0 U 0 0 0 eth0
[其它]
有待更新。
参考资料:
http://www.2cto.com/os/201203/125081.html
http://blog.chinaunix.net/uid-22646981-id-3048260.html
man手册
发表评论
-
VNC服务配置
2012-08-21 12:30 2417VNC服务配置 VNC (Virtual N ... -
arp
2012-08-13 13:59 1785[功能] 管理系统的arp缓存。 [描述] 用来管理系统的 ... -
tcpdump
2012-08-10 16:26 1709tcpdump [功能] 抓包工具 ... -
使用git进行版本控制
2012-06-14 18:05 19700使用git进行版本控制 ... -
netstat
2012-05-29 16:15 1635netstat [功能] netstat是一 ... -
关于存储管理中的一些概念
2011-11-17 17:49 1762关于存储管理中的一些概念 ... -
man命令
2011-10-30 09:54 1114man命令 若你想要找尋具 ... -
程序流程图绘制
2011-08-10 17:11 864dia windows http://sourceforge ... -
使用tnef打开*.dat的邮件
2011-08-10 16:06 1772有时,windows上面发送的mail是dat格式的,例如wi ... -
[转]jad反编译java
2011-08-04 11:14 1666jad 的使用方法 JAD本身 ... -
关于sizeof
2011-08-02 15:17 1248关于sizeof sizeof以字节形 ... -
wordpress备份和恢复
2011-07-14 17:42 2412wordpress备份和恢复 本文 ... -
wordpress恢复片段
2011-07-01 18:05 1155如何备份和恢复? 1,备份 假设在wordpress服务器上面 ... -
sorry I'm OoO
2011-07-01 10:41 826OOO(Out of Office)中文意思:在野;不执政; ... -
vim画图插件
2011-06-27 16:13 1305DrawIt:Vim画图插件(可在vim中画基本示意图) 还是 ... -
UML相关工具一览
2011-03-31 10:45 858http://www.umlchina.com/Tools/N ... -
解决“C compiler cannot create executables”的错误
2011-01-31 16:04 14390感觉不错的解决方法,还没有尝试过,先转载下来了。 解决“C ... -
svn 补充技巧
2010-12-03 14:07 3331http://hqlong.com/2009/02/641.h ... -
spinlock sample
2010-11-26 12:33 9122个使用spinlock的字符驱动完整例子 有待回去仔细验证 -
关于动迁
2010-10-15 16:27 989什么是动迁?拆迁?回 ...
相关推荐
配置 Route-Map 详解 Route-Map 是一种路由选择策略,允许 Network Administrator 根据不同的路由策略来选择路由。Route-Map 通常用于路由重发布、路由选择、路由过滤等场景。 配置 Route-Map 的步骤: 1. 配置...
### Linux网络工具iproute2的使用简介 #### 一、iproute2概述 iproute2是一套用于管理和控制TCP/IP网络以及流量控制的工具包,它在Linux环境下扮演着核心角色,尤其在现代Linux发行版中更为常见。iproute2的设计...
### Windows Route 命令详解 #### 概述 `route`命令是在Windows操作系统中用于管理本地IP路由表的强大工具。它可以用来查看当前的路由表、添加新的路由、删除现有路由或者修改现有的路由条目。这使得网络管理员或...
在Linux中,网络管理是非常重要的一部分,而`route`命令和`telnet`服务则是其中的关键工具。本文将深入探讨这两个概念及其在Linux系统,尤其是CentOS 6和7上的应用。 首先,`route`命令是Linux系统中的路由控制工具...
【华为ME60 V800R010C10SPC500配置指南 - OP-Route配置】 OP-Route(开放可编程路由)是华为ME60多业务控制网关中的一种路由策略,它允许用户通过控制器实现对路由的集中控制。这种路由方式基于控制器的选路规则,...
Route-map不错的路由过滤总结 Route-map 是一种强大的路由过滤工具,常用于路由协议之间的重分布、Policy-Based Routing(PBR)和 Border Gateway Protocol(BGP)。本文将对 Route-map 的配置和应用进行详细的总结...
Sorlaris 中 Route 命令详解 Sorlaris 中的 Route 命令是一种强大的网络路由管理工具,用于手动配置静态路由表,以便更好地控制网络流量和数据传输。下面将详细介绍 Sorlaris 中 Route 命令的使用方法和相关知识点...
《Route Generator 1.6汉化版:动态旅行路线图的制作神器》 在现代的数字生活中,规划旅行路线已经成为了一项重要的任务。对于旅行爱好者来说,拥有一款能够生成动态旅行路线图的工具无疑会大大提升行程规划的便捷...
Route 命令是 Windows 操作系统中的一种网络命令,用于显示和修改本地 IP 路由表中的条目。 Route 命令的主要功能是对本地 IP 路由表进行管理,包括添加、修改和删除路由条目。该命令可以用于设置静态路由、修改...
RouteOS是由Microtik公司开发的一款强大的路由器操作系统,主要用于网络设备的管理和配置。这款系统以其高效、稳定和功能丰富著称,尤其在企业级网络解决方案中广泛应用。标题提到的"RouteOS 5.26 已激活,不可升级6...
### Windows 下 `route` 命令详解 在Windows操作系统中,`route`命令是一个非常重要的网络工具,它主要用于查看和编辑本地计算机的IP路由表。通过使用`route`命令,用户可以添加、删除或更改计算机上的静态路由条目...
此资源有两个文件,含 nginx-upstream-jvm-route 和 nginx 对应版本,都是tar.gz文件。 安装方法网上很多就不写了,亲测可用。 不用担心版本不匹配造成安装失败,再浪费积分去到处下载尝试的烦恼。 此资源有两个文件...
Linux系统中的route命令能够用于IP路由表的显示和操作。它的主要作用是创建一个静态路由让指定一个主机或者一个网络通过一个网络接口,如eth0。当使用”add”或者”del”参数时,路由表被修改,如果没有参数,则显示...
《WlanRoute:一款便捷的WiFi共享工具》 在当今数字化时代,WiFi已经成为人们日常生活中不可或缺的一部分。无论是工作、学习还是娱乐,我们都离不开稳定的网络连接。而“WlanRoute”便是一款专为用户打造的简单易用...
"Route-Map 在 Redistribute 和 Policy-Routing 中的应用及注意点" Route-Map 是一种强大的路由策略工具,能够应用在两种不同的地方:Redistribute 和 Policy-Routing。但是,区别必须搞清楚,以免带来不必要的麻烦...
【标题】"nginx-upstream-jvm-route-1.15" 涉及的核心知识点是Nginx的upstream模块与JVM路由的整合,特别针对Nginx 1.15版本。这个项目旨在解决在配置Nginx时遇到的特定错误提示“nginx: [emerg] invalid parameter ...
### Windows系统route命令详解 #### 一、概述 在Windows操作系统中,`route`命令是一项重要的网络工具,用于查看和管理计算机的IP路由表。通过使用`route`命令,管理员可以手动添加、删除或者更改静态路由条目,这...
Route 是 Vue.js 中的路由管理器,用于实现单页面应用(SPA)中的页面跳转和导航。 在 "Vue3+vite+axios+route" 示例项目中,我们可以学习到以下几个关键知识点: 1. **Vue3 特性**: - **Composition API**:Vue...
### IP Route 命令手册知识点详解 #### 1. 关于IP Route命令与文档 `ip route`命令是Linux操作系统中用于网络配置的核心工具,它隶属于iproute2软件包,取代了传统的网络管理工具如`ifconfig`和`route`。这份手册...
《WlanRoute自建热点工具:打造个人移动网络中心》 在现代数字化社会,无线网络已经成为日常生活和工作中不可或缺的一部分。特别是在没有固定网络接入或者需要共享网络的场合,自建热点的功能显得尤为重要。"Wlan...