设为首页 收藏本站
查看: 540|回复: 0

[经验分享] linux和windows如何添加路由

[复制链接]
YunVN网友  发表于 2018-6-15 13:20:28 |阅读模式
linux路由的添加对于我们来说很重要,有的时候网络不通,也许就是你路由没加,发出来,希望对大家有所帮助!  服务器ip(eth0)
  [root@localhost net]# ifconfig
  eth0    Link encap:Ethernet   HWaddr 00:0C:29:E3:9A:15
  inet addr:172.18.3.205   Bcast:172.18.3.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.18.3.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.18.3.50
  [root@localhost net]# route
  Kernel IP routing table
  Destination     Gateway       Genmask       Flags Metric Ref Use Iface
  172.18.3.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.18.3.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.18.3.205   Bcast:172.18.3.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.18.3.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.18.3.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.18.3.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.18.3.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 *     &nb
  sp;       255.255.255.255 UH 0    0        0 eth0
  172.18.3.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.18.3.50     0.0.0.0       UG 0    0        0 eth0
  ===========================================================
  添加到网络的路由(通过eth0)
  [root@localhost net]# route add -net 192.168.3.0 netmask 255.255.255.0 dev eth0
  [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 *             255.255.255.255 UH 0    0        0 eth0
  192.168.3.0     *             255.255.255.0 U     0    0        0 eth0
  172.18.3.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.18.3.50     0.0.0.0       UG 0    0        0 eth0
  添加到网络的路由(通过ip172.18.3.50)
  [root@localhost net]# route add -net 192.168.4.0 netmask 255.255.255.0 gw 172.18.3.50
  [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 *             255.255.255.255 UH 0    0        0 eth0
  192.168.4.0     172.18.3.50     255.255.255.0 UG 0    0        0 eth0
  192.168.3.0     *             255.255.255.0 U     0    0        0 eth0
  172.18.3.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.18.3.50     0.0.0.0       UG 0    0        0 eth0
  =======================================================================
  参数区别-host跟主机ip,-net跟网络号
  =======================================================================
  输出结果中各个字段的含义是:
  Destination表示路由的目标IP地址
  Gateway表示网关使用的主机名或者是IP地址。上面输出的"*"表示没有网关
  Genmask表示路由的网络掩码
  Flags是表示路由的标志。可用的标志及其意义是:U表示路由在启动,H表示target是一台主机,G表示使用网关,R表示对动态路由进行复位设置;D表示动态安装路由,M表示修改路由,!表示拒绝路由。
  Metric表示路由的单位开销量
  Ref表示依赖本路由现状的其它路由数目
  Use表示路由表条目被使用的数目
  Iface表示路由所发送的包的目的网络

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-524251-1-1.html 上篇帖子: 如何挽救崩溃的Windows XP操作系统 下篇帖子: Windows 文件过滤驱动经验总结
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表