运维route语法
Linux系统的route命令用于显示和操作IP路由表(show / manipulate the IP routing table)。要实现两个不同的子网之间的通信,需要一台连接两个网络的路由器,或者同时位于两个网络的网关来实现。在Linux系统中,设置路由通常是为了解决以下问题:该Linux系统在一个局域网中,局域网中有一个网关,能够让机器访问Internet,那么就需要将这台机器的IP地址设置为Linux机器的默认路由。要注意的是,直接在命令行下执行route命令来添加路由,不会永久保存,当网卡重启或者机器重启之后,该路由就失效了;可以在/etc/rc.local中添加route命令来保证该路由设置永久有效。
1.命令格式:
route [-f] [-p] [Command [Destination] [mask Netmask] [Gateway] [metric Metric]] [if Interface]]
2.命令功能:
Route命令是用于操作基于内核ip路由表,它的主要作用是创建一个静态路由让指定一个主机或者一个网络通过一个网络接口,如eth0。当使用"add"或者"del"参数时,路由表被修改,如果没有参数,则显示路由表当前的内容。
3.命令参数:
-c 显示更多信息
-n 不解析名字
-v 显示详细的处理信息
-F 显示发送信息
-C 显示路由缓存
-f 清除所有网关入口的路由表。
-p 与 add 命令一起使用时使路由具有永久性。
add:添加一条新路由。
del:删除一条路由。
-net:目标地址是一个网络。
-host:目标地址是一个主机。
netmask:当添加一个网络路由时,需要使用网络掩码。
gw:路由数据包通过网关。注意,你指定的网关必须能够达到。
metric:设置路由跳数。
Command 指定您想运行的命令 (Add/Change/Delete/Print)。
Destination 指定该路由的网络目标。
mask Netmask 指定与网络目标相关的网络掩码(也被称作子网掩码)。
Gateway 指定网络目标定义的地址集和子网掩码可以到达的前进或下一跃点 IP 地址。
metric Metric 为路由指定一个整数成本值标(从 1 至 9999),当在路由表(与转发的数据包目标地址最匹配)的多个路由中进行选择时可以使用。
if Interface 为可以访问目标的接口指定接口索引。若要获得一个接口列表和它们相应的接口索引,使用 route print 命令的显示功能。可以使用十进制或十六进制值进行接口索引。
4.使用实例:
实例1:显示当前路由
命令:
route
route -n
输出:
- [root@localhost ~]# route
- Kernel IP routing table
- Destination Gateway Genmask Flags Metric Ref Use Iface
- 192.168.120.0 * 255.255.255.0 U 0 0 0 eth0
- e192.168.0.0 192.168.120.1 255.255.0.0 UG 0 0 0 eth0
- 10.0.0.0 192.168.120.1 255.0.0.0 UG 0 0 0 eth0
- default 192.168.120.240 0.0.0.0 UG 0 0 0 eth0
- [root@localhost ~]# route -n
- Kernel IP routing table
- Destination Gateway Genmask Flags Metric Ref Use Iface
- 192.168.120.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
- 192.168.0.0 192.168.120.1 255.255.0.0 UG 0 0 0 eth0
- 10.0.0.0 192.168.120.1 255.0.0.0 UG 0 0 0 eth0
- 0.0.0.0 192.168.120.240 0.0.0.0 UG 0 0 0 eth0
说明:
第一行表示主机所在网络的地址为192.168.120.0,若数据传送目标是在本局域网内通信,则可直接通过eth0转发数据包;
第四行表示数据传送目的是访问Internet,则由接口eth0,将数据包发送到网关192.168.120.240
其中Flags为路由标志,标记当前网络节点的状态。
Flags标志说明:
U Up表示此路由当前为启动状态
H Host,表示此网关为一主机
G Gateway,表示此网关为一路由器
R Reinstate Route,使用动态路由重新初始化的路由
D Dynamically,此路由是动态性地写入
M Modified,此路由是由路由守护程序或导向器动态修改
! 表示此路由当前为关闭状态
备注:
route -n (-n 表示不解析名字,列出速度会比route 快)
实例2:添加网关/设置网关
命令:
route add -net 224.0.0.0 netmask 240.0.0.0 dev eth0
输出:
- [root@localhost ~]# route add -net 224.0.0.0 netmask 240.0.0.0 dev eth0
- [root@localhost ~]# route
- Kernel IP routing table
- Destination Gateway Genmask Flags Metric Ref Use Iface
- 192.168.120.0 * 255.255.255.0 U 0 0 0 eth0
- 192.168.0.0 192.168.120.1 255.255.0.0 UG 0 0 0 eth0
- 10.0.0.0 192.168.120.1 255.0.0.0 UG 0 0 0 eth0
- 224.0.0.0 * 240.0.0.0 U 0 0 0 eth0
- default 192.168.120.240 0.0.0.0 UG 0 0 0 eth0
[root@localhost ~]#
说明:
增加一条 到达244.0.0.0的路由
实例3:屏蔽一条路由
命令:
route add -net 224.0.0.0 netmask 240.0.0.0 reject
输出:
- [root@localhost ~]# route add -net 224.0.0.0 netmask 240.0.0.0 reject
- [root@localhost ~]# route
- Kernel IP routing table
- Destination Gateway Genmask Flags Metric Ref Use Iface
- 192.168.120.0 * 255.255.255.0 U 0 0 0 eth0
- 192.168.0.0 192.168.120.1 255.255.0.0 UG 0 0 0 eth0
- 10.0.0.0 192.168.120.1 255.0.0.0 UG 0 0 0 eth0
- 224.0.0.0 - 240.0.0.0 ! 0 - 0 -
- 224.0.0.0 * 240.0.0.0 U 0 0 0 eth0
- default 192.168.120.240 0.0.0.0 UG 0 0 0 eth0
说明:
增加一条屏蔽的路由,目的地址为 224.x.x.x 将被拒绝
实例4:删除路由记录
命令:
route del -net 224.0.0.0 netmask 240.0.0.0
route del -net 224.0.0.0 netmask 240.0.0.0 reject
输出:
- [root@localhost ~]# route
- Kernel IP routing table
- Destination Gateway Genmask Flags Metric Ref Use Iface
- 192.168.120.0 * 255.255.255.0 U 0 0 0 eth0
- 192.168.0.0 192.168.120.1 255.255.0.0 UG 0 0 0 eth0
- 10.0.0.0 192.168.120.1 255.0.0.0 UG 0 0 0 eth0
- 224.0.0.0 - 240.0.0.0 ! 0 - 0 -
- 224.0.0.0 * 240.0.0.0 U 0 0 0 eth0
- default 192.168.120.240 0.0.0.0 UG 0 0 0 eth0
- [root@localhost ~]# route del -net 224.0.0.0 netmask 240.0.0.0
- [root@localhost ~]# route
- Kernel IP routing table
- Destination Gateway Genmask Flags Metric Ref Use Iface
- 192.168.120.0 * 255.255.255.0 U 0 0 0 eth0
- 192.168.0.0 192.168.120.1 255.255.0.0 UG 0 0 0 eth0
- 10.0.0.0 192.168.120.1 255.0.0.0 UG 0 0 0 eth0
- 224.0.0.0 - 240.0.0.0 ! 0 - 0 -
- default 192.168.120.240 0.0.0.0 UG 0 0 0 eth0
- [root@localhost ~]# route del -net 224.0.0.0 netmask 240.0.0.0 reject
- [root@localhost ~]# route
- Kernel IP routing table
- Destination Gateway Genmask Flags Metric Ref Use Iface
- 192.168.120.0 * 255.255.255.0 U 0 0 0 eth0
- 192.168.0.0 192.168.120.1 255.255.0.0 UG 0 0 0 eth0
- 10.0.0.0 192.168.120.1 255.0.0.0 UG 0 0 0 eth0
- default 192.168.120.240 0.0.0.0 UG 0 0 0 eth0
- [root@localhost ~]#
说明:
实例5:删除和添加设置默认网关
命令:
route del default gw 192.168.120.240
route add default gw 192.168.120.240
输出:
- [root@localhost ~]# route del default gw 192.168.120.240
- [root@localhost ~]# route
- Kernel IP routing table
- Destination Gateway Genmask Flags Metric Ref Use Iface
- 192.168.120.0 * 255.255.255.0 U 0 0 0 eth0
- 192.168.0.0 192.168.120.1 255.255.0.0 UG 0 0 0 eth0
- 10.0.0.0 192.168.120.1 255.0.0.0 UG 0 0 0 eth0
- [root@localhost ~]# route add default gw 192.168.120.240
- [root@localhost ~]# route
- Kernel IP routing table
- Destination Gateway Genmask Flags Metric Ref Use Iface
- 192.168.120.0 * 255.255.255.0 U 0 0 0 eth0
- 192.168.0.0 192.168.120.1 255.255.0.0 UG 0 0 0 eth0
- 10.0.0.0 192.168.120.1 255.0.0.0 UG 0 0 0 eth0
- default 192.168.120.240 0.0.0.0 UG 0 0 0 eth0
- [root@localhost ~]#
运维route语法的更多相关文章
- 运维ldd语法--》ldconfig
Linux:ldd命令详解 ldd 用于打印程序或者库文件所依赖的共享库列表. 语法 ldd(选项)(参数) 选项 --version:打印指令版本号: -v:详细信息模式,打印所有相关信息: - ...
- 运维ip语法,DNS配置方法
修改配置文件: /etc/resolv.conf nameserver DNS_IP_1 nameserver DNS_IP_2 nameserver 指定本机解析: /etc/hosts 主机IP ...
- 运维chroot语法
chroot命令 chroot命令用来在指定的根目录下运行指令.chroot,即 change root directory (更改 root 目录).在 linux 系统中,系统默认的目录结构都是以 ...
- 运维ps语法---》ps、pstree、top、htop、nice、renice、kill、ulimit、w 和 who 和 whoami、pgrep、fg 和 bg、ipcs
Linux中的ps命令是Process Status的缩写.ps命令用来列出系统中当前运行的那些进程.ps命令列出的是当前那些进程的快照,就是执行ps命令的那个时刻的那些进程,如果想要动态的显示进程信 ...
- 运维rpm语法
Linux软件包分类 rpm 常用命令1.安装一个包 # rpm -ivh 2.升级一个包 # rpm -Uvh 3.卸载一个包 # rpm -e 4.安装参数 --force 即使覆盖属于其它包的文 ...
- 运维seq语法
seq-print a sequence of numbers 用于产生从某个数到另外一个数之间的所有整数 语法:seq 开始列 指定步长 结束列 参数: -f :指定输出格式,允许使用print ...
- 运维grep语法
grep的语法和用法 grep命令的格式: grep [options] PATTERN [FILE] 其中:1,pattern是用正则表达式书写的模式.2,FILE是要查找的文件,可以是用 ...
- 运维nslookup语法
nslookup 查询域名DNS信息的工具 补充说明 nslookup命令 是常用域名查询工具,就是查DNS信息用的命令. nslookup4有两种工作模式,即“交互模式”和“非交互模式”.在“交互模 ...
- 运维dig语法
dig命令是常用的域名查询工具,可以用来测试域名系统工作是否正常 语法 1 dig(选项)(参数) 选项 1 @<服务器地址>:指定进行域名解析的域名服务器: 2 -b<ip地址&g ...
随机推荐
- ionic3 在windows环境下打包android 正式签名版APK
生成签名文件keytool -genkey -alias demo.keystore -keyalg RSA -validity 40000 -keystore demo.keystore demo为 ...
- android -------- Hawk数据库
Hawk 是一个非常便捷的数据库 . 操作数据库只需一行代码 , 能存任何数据类型 . github 地址: https://github.com/orhanobut/hawk 一.概念 Share ...
- scrapy 中crawlspider 爬虫
爬取目标网站: http://www.chinanews.com/rss/rss_2.html 获取url后进入另一个页面进行数据提取 检查网页: 爬虫该页数据的逻辑: Crawlspider爬虫类: ...
- 20165309 《网络对抗技术》实验一:PC平台逆向破解
20165309 <网络对抗技术>实验一:PC平台逆向破解 目录 实践目标 基础知识 实验原理.内容及步骤 问题与解决 实验收获 一.实践目标 本次实践的对象是一个名为pwn1的linux ...
- Activiti流程变量五步曲 ——by fightingKing
http://blog.csdn.net/zwk626542417/article/details/46648139 一.前言 上一篇文章我们将流程实例的启动与查询,任务的办理查询都进行了介绍,我们这 ...
- Vue2全家桶之二:vue-router(路由)详细教程,看这个就够了
作者:东西里本文转载于:https://www.jianshu.com/p/514c7588e877来源:简书 转载仅供自己日后看方便. 由于Vue在开发时对路由支持的不足,于是官方补充了vue- ...
- echarts-五分钟的教程
https://echarts.baidu.com/tutorial.html#5%20%E5%88%86%E9%92%9F%E4%B8%8A%E6%89%8B%20ECharts
- 2015-10-27 C#3
三.字符串拼凑stringbuilder stringbuilder sb= new stringbuilder(); sb.append("aaa"); sb.append(&q ...
- js 快速生成数组的方法
//实现方法一:循环赋值var arr1 = new Array(100);for(var i=0;i<arr1.length;i++){ arr1[i] = i;}console.log(ar ...
- CentOS 7系统上制作Clonezilla(再生龙)启动U盘并克隆双系统
笔记本安装的是双系统:Win7 64位,CentOS 7 64位. 政采就是个巨大的坑,笔记本标配的是5400转的机械硬盘,开机时间常常要一至两分钟,软件运行起来时各种数据的读写也非常慢,忍无可忍,决 ...