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



相关文章
|
1月前
|
Linux Shell Windows
通过Linux挂载Windows端NFS服务实现板端Linux传输文件到PC
通过Linux挂载Windows端NFS服务实现板端Linux传输文件到PC
|
10天前
|
关系型数据库 MySQL Linux
linux CentOS 7.4下 mysql5.7.20 密码改简单的方法
linux CentOS 7.4下 mysql5.7.20 密码改简单的方法
17 0
|
17天前
|
Ubuntu Linux
常用Linux开机启动添加方法
常用Linux开机启动添加方法
13 1
|
1月前
|
安全 Linux 开发者
⭐⭐⭐⭐⭐Linux C/C++ 进程崩溃诊断以及有效数据收集:解锁代码问题快速定位与修复的方法
⭐⭐⭐⭐⭐Linux C/C++ 进程崩溃诊断以及有效数据收集:解锁代码问题快速定位与修复的方法
77 1
|
4天前
|
SQL 监控 安全
Linux&Windows 日志分析 陇剑杯 CTF
Linux&Windows 日志分析 陇剑杯 CTF
29 0
|
7天前
|
Linux Windows
Windows、Mac、Linux解决端口被占用的问题
Windows、Mac、Linux解决端口被占用的问题
8 1
|
10天前
|
Linux Shell 虚拟化
linux 部署docker容器虚拟化平台(二)--------docker 镜像制作方法
linux 部署docker容器虚拟化平台(二)--------docker 镜像制作方法
15 0
|
12天前
|
监控 Linux
|
14天前
|
安全 Ubuntu Linux
Linux远程访问Windows实现步骤
在Windows上启用远程桌面连接并获取IP地址后,Linux用户需安装SSH客户端( Debian系:`sudo apt-get update; sudo apt-get install openssh-client`,RPM系:`sudo yum install openssh-clients`)。然后使用命令`ssh 用户名@Windows_IP地址`连接,其中`用户名`和`Windows_IP地址`按实际情况填写。
14 4
|
16天前
|
存储 缓存 监控
深入解析linux内存指标:快速定位系统内存问题的有效技巧与实用方法(free、top、ps、vmstat、cachestat、cachetop、sar、swap、动态内存、cgroops、oom)
深入解析linux内存指标:快速定位系统内存问题的有效技巧与实用方法(free、top、ps、vmstat、cachestat、cachetop、sar、swap、动态内存、cgroops、oom)