linux和windows路由条目添加方法。

简介:

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
作用同上,添加 一条永久静态路由,不会因为重启机器而丢失,-p选项表示保存.

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 -net 192.168.9.253 netmask 255.255.255.255 gw 192.168.31.254

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

//删除路由
# route del –host 192.168.168.110 dev eth0

# route del -net 192.168.9.253 netmask 255.255.255.255 gw 192.168.31.254

参数解释:

add 增加路由
del 删除路由
-net 设置到某个网段的路由
-host 设置到某台主机的路由
gw 出口网关 IP地址
dev 出口网关 物理设备名


二:在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/network-script/route-eth0:

   如没有route-eth0则创建名为route- eth0的文件
   vim /etc/sysconfig/network-script/route-eth0
  在此文件添加如下格式的内容
  192.168.1.0/24 via 192.168.0.1

   via 网关出口 IP地址
   dev 网关出口 物理设备名


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

服务器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@centos6 ~]# netstat -rn
Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
192.168.16.0    0.0.0.0         255.255.240.0      U           0        0        eth0
0.0.0.0         192.168.30.10   0.0.0.0              UG           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

在查看路由信息
[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 *

本文转自 boy461205160 51CTO博客,原文链接:http://blog.51cto.com/461205160/1735231



相关文章
|
6天前
|
iOS开发 MacOS Windows
|
1天前
|
Linux 网络安全
xmanager 4 连接SuSE linux server 11方法
xmanager 4 连接SuSE linux server 11方法
|
1天前
|
Linux
【Linux】命名管道的创建方法&&基于命名管道的两个进程通信的实现
【Linux】命名管道的创建方法&&基于命名管道的两个进程通信的实现
|
3天前
|
NoSQL Linux Redis
Redis的介绍,以及Redis的安装(本机windows版,虚拟机Linux版)和Redis常用命令的介绍
Redis的介绍,以及Redis的安装(本机windows版,虚拟机Linux版)和Redis常用命令的介绍
17 0
|
4天前
|
Shell Linux 编译器
C语言,Linux,静态库编写方法,makefile与shell脚本的关系。
总结:C语言在Linux上编写静态库时,通常会使用Makefile来管理编译和链接过程,以及Shell脚本来自动化构建任务。Makefile包含了编译规则和链接信息,而Shell脚本可以调用Makefile以及其他构建工具来构建项目。这种组合可以大大简化编译和构建过程,使代码更易于维护和分发。
21 5
|
5天前
|
Shell Linux 编译器
C语言,Linux,静态库编写方法,makefile与shell脚本的关系。
总结:C语言在Linux上编写静态库时,通常会使用Makefile来管理编译和链接过程,以及Shell脚本来自动化构建任务。Makefile包含了编译规则和链接信息,而Shell脚本可以调用Makefile以及其他构建工具来构建项目。这种组合可以大大简化编译和构建过程,使代码更易于维护和分发。
14 3
|
9天前
|
Windows
Windows 程序自启动实现方法详解
Windows 程序自启动实现方法详解
26 0
|
10天前
|
Ubuntu Unix Linux
|
11天前
|
前端开发 Linux iOS开发
【Flutter前端技术开发专栏】Flutter在桌面应用(Windows/macOS/Linux)的开发实践
【4月更文挑战第30天】Flutter扩展至桌面应用开发,允许开发者用同一代码库构建Windows、macOS和Linux应用,提高效率并保持平台一致性。创建桌面应用需指定目标平台,如`flutter create -t windows my_desktop_app`。开发中注意UI适配、性能优化、系统交互及测试部署。UI适配利用布局组件和`MediaQuery`,性能优化借助`PerformanceLogging`、`Isolate`和`compute`。
【Flutter前端技术开发专栏】Flutter在桌面应用(Windows/macOS/Linux)的开发实践