<!-- /* Font Definitions */ @font-face {font-family:宋体; panose-1:2 1 6 0 3 1 1 1 1 1; mso-font-alt:SimSun; mso-font-charset:134; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:3 135135232 16 0 262145 0;} @font-face {font-family:"/@宋体"; panose-1:2 1 6 0 3 1 1 1 1 1; mso-font-charset:134; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:3 135135232 16 0 262145 0;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {mso-style-parent:""; margin:0cm; margin-bottom:.0001pt; text-align:justify; text-justify:inter-ideograph; mso-pagination:none; font-size:10.5pt; mso-bidi-font-size:12.0pt; font-family:"Times New Roman"; mso-fareast-font-family:宋体; mso-font-kerning:1.0pt;} a:link, span.MsoHyperlink {color:blue; text-decoration:underline; text-underline:single;} a:visited, span.MsoHyperlinkFollowed {color:navy; text-decoration:underline; text-underline:single;} /* Page Definitions */ @page {mso-page-border-surround-header:no; mso-page-border-surround-footer:no;} @page Section1 {size:595.3pt 841.9pt; margin:72.0pt 90.0pt 72.0pt 90.0pt; mso-header-margin:42.55pt; mso-footer-margin:49.6pt; mso-paper-source:0; layout-grid:15.6pt;} div.Section1 {page:Section1;} -->
□————○————○————○————□
PC1 ROUT1 ROUT2 ROUT3 PC2
五个设备的静态IP地址分别为:
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 [up/down(enable/disable)]
#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),用下面的命令完成
#echo 1 > /proc/sys/net/ipv4/ip_forward
网络重启后,上面的文件自动改为0
常用命令:
1、删除默认路由#route del default,添加默认网关#route add default gw IP
2、查看路由#route –n或者netstat -r 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 add –host 192.168.4.55 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
5、激活(禁用)设备ifconfig eth0:1 up(down)
6、查看所有(指定)网络接口配置ifconfig (eth0)
常用配置文件:
/etc/sysconfig/network系统路由配置
/etc/sysconfig/nework-script/ifcfg-ethX网卡路由配置
/etc/sysconfig/networking/device/ethX.route静态路由配置
/etc/xinetd.conf 定义了由超级进程XINETD启动的网络服务
/etc/protocols 设定了主机使用的协议以及各个协议的协议号
/etc/services 设定了主机的不同端口的网络服务