CentOS 6.9永久设置静态路由表以及路由表常用设置
一、路由表常用设置:
1、使用route命令添加的路由,机器重启或者网卡重启后路由就失效了,方法:
//添加到主机的路由
# route add –host 192.168.1.11 dev eth0
# route add –host 192.168.1.12 gw 192.168.1.1 //添加到网络的路由
# route add –net 192.168.1.11 netmask 255.255.255.0 dev eth0
# route add –net 192.168.1.11 netmask 255.255.255.0 gw 192.168.1.1
# route add –net 192.168.1.0/ dev eth1 //添加默认网关
# route add default gw 192.168.2.1 //删除路由
# route del –host 192.168.1.11 dev eth0
2、还可以使用ip命令来添加、删除路由
//添加
ip route add default via 172.16.10.2 dev eth0
ip route add 172.16.1.0/ via 172.16.10.2 dev eth0
3、查询
# netstat -nr
# route -n
# ip route list
# ip route show
二、永久设置路由表:
方法一:在/etc/sysconfig/network配置文件中配置(我测试了好像不太可行):
default via 192.168.3.1 dev eth0 #192.168..1为eth0网卡的网关地址
10.211.6.0/ via 192.168.3.1 dev eth0
10.0.0.0/ via 10.212.52.1 dev eth1 #10.212..1为eth1网卡的网关地址
注:该种配置写法同样支持写到/etc/sysconfig/network-scripts/route-interferface配置文件中。
具体可以参看redhat官方文档。
方法二:在/etc/sysconfig/network-scripts/route-{interferface}配置文件配置({interferface}为网卡接口,如eth0)
在这里支持两种配置格式的写法
A:方法1中提到的方法
# cat /etc/sysconfig/network-scripts/route-eth0
0.0.0.0/ via 192.168.3.1 dev eth0
10.211.6.0/ via 192.168.3.1 dev eth0
# cat /etc/sysconfig/network-scripts/route-eth1
10.0.0.0/ via 10.212.52.1 dev eth1
B:网络掩码法(投机取巧,走漏洞)
# cat /etc/sysconfig/network-scripts/route-eth0
ADDRESS0=0.0.0.0
NETMASK0=0.0.0.0
GATEWAY0=192.168.3.1
ADDRESS1=10.211.6.0
NETMASK1=255.255.255.0
GATEWAY1=192.168.3.1
其中网段地址和掩码全是0代表为所有网段,即默认路由。
# cat /etc/sysconfig/network-scripts/route-eth1
ADDRESS0=10.0.0.0
NETMASK0=255.0.0.0
GATEWAY0=10.212.52.1
网络掩码法也可以参看redhat官方文档。
方法三:/etc/sysconfig/static-routes配置(推荐)
# cat /etc/sysconfig/static-route
any net any gw 192.168.3.1
any net 10.211.6.0/ gw 192.168.3.1
any net 10.0.0.0 netmask 255.0.0.0 gw 10.212.52.1
注:默认情况下主机中并没有该文件,需要手动创建。net是范围,host可以单独指定某一台机器。
之所以该方法也可以是因为/etc/init.d/network启动脚本会调用该文件,具体调用部分代码原理如下:
# Add non interface-specific static-routes.
if [ -f /etc/sysconfig/static-routes ]; then
grep "^any" /etc/sysconfig/static-routes | while read ignore args ; do
/sbin/route add -$args
done
fi
方法四:写在开机脚本/etc/rc.local
route add -net 10.8.0.0 255.255.255.0 gw 192.168.199.2
参考:
http://www.361way.com/linux-define-static-route/4053.html(以上内容转自此篇文章)
http://dev.dafan.info/detail/221534
http://www.jb51.net/article/101683.htm
https://segmentfault.com/a/1190000004165066
http://network.chinabyte.com/194/11200694.shtml
CentOS 6.9永久设置静态路由表以及路由表常用设置的更多相关文章
- ubuntu 15.10 设置静态ip 分配固定ip 设置dns 设置网关 命令行配置ip 固定ip不生效怎么办
要用到的文件: 配置接口信息 /etc/network/interfaces 配置内容: auto eth0 iface eth0 inet static address 192.168.216.18 ...
- Virtualbox Ubuntu 虚拟机命令行挂载共享文件夹及设置静态IP
挂载共享文件夹 参考 [1], VirtualBox/GuestAdditions [2], VirtualBox/SharedFolders 步骤 在Virtualbox 虚拟机的菜单『设备』中,点 ...
- VMware虚拟机安装Centos7后设置静态ip
VMware虚拟机安装Centos7后设置静态ip 1. 先设置虚拟机的网络,打开虚拟网络编辑器: 2. 选择Vm8 234都要勾选 3. 打开NAT设置,看到123,待会要用. 4. 打开虚拟机服务 ...
- IntelliJ IDEA 常用设置/快捷键
经常用到 IntelliJ IDEA 编写java,由于不时需要重装系统,所以Mark一下一些基本的设置选项,以便查询,这篇帖子会一直更新,只要有常用的新的设置或者快捷键 一.常用设置 显示代码行号 ...
- 解决CentOS添加新网卡后找不到网卡配置文件,配置多网卡并设置静态路由
参考文章 https://blog.csdn.net/qq_36512792/article/details/79787649 使用VMware Workstation虚拟机安装好CentOS7虚拟机 ...
- Ubantu和CentOS设置静态ip
Ubantu设置ip: 1.sudo vim /etc/NetworkManager/NetworkManager.conf 将false改成true 2.修改配置文件/etc/network/int ...
- CentOS设置静态IP及Samba等基础设置
1. CentOS7设置静态IP CentOS的网卡IP配置文件/etc/sysconfig/network-scripts/ifcfg-网卡名字. 配置参数解析: BOOTPROTO="s ...
- Centos 7设置静态IP,修改时区,关闭防火墙
Centos 7设置静态IP # vi /etc/sysconfig/network-scripts/ifcfg-enxxx BOOTPROTO="static" ...... I ...
- CentOS 6.5、6.7 设置静态 ip 教程
CentOS 6.5.6.7 设置静态 ip 教程,可以ping通外网:www.baidu.com ①. 网络适配器(VMware Network Adapter) 选择NAT模式 ②. 设置静态 i ...
随机推荐
- shell 监控磁盘使用率【转】
方案一: disks=(`df |sed 1d | awk '{print $1,$5}'|tr -d %`) len=${#disks[@]} ;i<=$len;i=i+));do ];the ...
- 判断Selenium加载完成
How do you make Selenium 2.0 wait for the page to load? You can also check pageloaded using followin ...
- [转载]锁无关的数据结构与Hazard指针——操纵有限的资源
Lock-Free Data Structures with Hazard Pointers 锁无关的数据结构与Hazard指针----操纵有限的资源 By Andrei Alexandrescu a ...
- URL中斜杠/和反斜杠\的区别小结
Unix使用斜杆/ 作为路径分隔符,而web应用最新使用在Unix系统上面,所以目前所有的网络地址都采用 斜杆/ 作为分隔符. Windows由于使用 斜杆/ 作为DOS命令提示符的参数标志了,为了不 ...
- U3D的一些常用基础脚本
修改渲染颜色和贴图 1: var texture :Texture ; 2: 3: function Start () { 4: renderer.material.mainTexture = te ...
- js监测设备类型【安卓,ios,苹果微信,电脑pc】
话不多说上代码: 1.判断是不是微信 function is_weixn(){ var ua = navigator.userAgent.toLowerCase(); if(ua.match(/Mic ...
- LoadRunner中常用的字符串操作函数
LoadRunner中常用的字符串操作函数有: strcpy(destination_string, source_string); strc ...
- oracle 内连接、外连接、自然连接、交叉连接练习
oracle 内连接.外连接.自然连接.交叉连接练习 --查询员工信息 select * from emp; --查询部门信息 select * from dept; --需求:查询员工姓名.薪资和所 ...
- poj1573 Robot Motion(DFS)
题目链接 http://poj.org/problem?id=1573 题意 一个机器人在给定的迷宫中行走,在迷宫中的特定位置只能按照特定的方向行走,有两种情况:①机器人按照方向序列走出迷宫,这时输出 ...
- Java经典设计模式之五大创建型模式
转载: Java经典设计模式之五大创建型模式 一.概况 总体来说设计模式分为三大类: (1)创建型模式,共五种:工厂方法模式.抽象工厂模式.单例模式.建造者模式.原型模式. (2)结构型模式,共七种: ...