1. 查看IP
//查看本机地址
[root@mike /]#ifconfig
eth0 Link encap:Ethernet HWaddr 36:65:12:08:47:70
inet addr:192.168.1.200 Bcast:192.168.1.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:196 errors:0 dropped:0 overruns:0 frame:0
TX packets:7 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:19450 (18.9 KiB) TX bytes:498 (498.0 B)
2. 配置静态主机路由
//添加主机路由,在-host后面用的是本地的地址,意思是将地址192.168.1.200发送数据都要要转发到路由器网关192.168.1.1上。
[root@mike/]#route add -host 192.168.1.200 gw 192.168.1.1 dev eth0
//查看主机路由信息
[root@mike/]#route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
default * 0.0.0.0 U 0 0 0 ppp0
10.0.0.1 * 255.255.255.255 UH 0 0 0 ppp0
192.168.1.0 * 255.255.255.0 U 0 0 0 eth0
192.168.1.200 192.168.1.1 255.255.255.255 UGH 0 0 0 eth0
3. 配置静态网络路由
//本地主机将发送到网络192.168.1的数据包转发到IP地址为192.168.1.1的路由器上。
[root@mike/]#route add -net 192.168.1.0/24 gw 192.168.1.1 dev eth0
//查看网络路由信息
[root@mike/]#route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
default * 0.0.0.0 U 0 0 0 ppp0
10.0.0.1 * 255.255.255.255 UH 0 0 0 ppp0
192.168.1.0 192.168.1.1 255.255.255.0 UG 0 0 0 eth0
192.168.1.0 * 255.255.255.0 U 0 0 0 eth0
4. 范例
主机路由:机路由是路由选择表中指向单个IP地址或主机名的路由记录。主机路由的Flags字段为H。
Destination Gateway Genmask Flags Metric Ref Use Iface
----------- ------- ------- ----- ------ --- --- -----
10.0.0.10 192.168.1.1 255.255.255.255 UH 0 0 0 eth0
网络路由:网络路由是代表主机可以到达的网络。网络路由的Flags字段为N。例如,在下面的示例中,本地主机将发送到网络192.19.12的数据包转发到IP地址为192.168.1.1的路由器。
Destination Gateway Genmask Flags Metric Ref Use Iface
----------- ------- ------- ----- ----- --- --- -----
192.19.12 192.168.1.1 255.255.255.0 UN 0 0 0 eth0
默认路由:当主机不能在路由表中查找到目标主机的IP地址或网络路由时,数据包就被发送到默认路由(默认网关)上。默认路由的Flags字段为G。
Destination Gateway Genmask Flags Metric Ref Use Iface
----------- ------- ------- ----- ------ --- --- -----
default 192.168.1.1 0.0.0.0 UG 0 0 0 eth0