CentOS 6 配置静态IP及路由

CentOS 6 配置静态IP及路由

一.手动改网卡

step1:vim /etc/udev/rules.d/70-persistent-net.rules
将其中对应的要修改的网卡最后的NAME=eth* 改为对应的名称

CentOS 6 配置静态IP及路由

step2:modprobe -r e1000卸载网卡模块(这里因为知道了网卡模块是e1000)
            查询网卡模块的命令是 ethtool -i eth2 查看驱动模块名

CentOS 6 配置静态IP及路由

step3:modprobe e1000 加载网卡模块
step4:cd /etc/sysconfig/network-scripts中将原网卡的配置文件改名,格式为 ifcfg-网卡名

CentOS 6 配置静态IP及路由

step5:修改上述配置文件,将其中的DEVICE=改为网卡名 将其中的DDR改为对应的MAC地址

CentOS 6 配置静态IP及路由

step6:ifdown网卡名
step7:ifup网卡名

二.手动改路由

step1:vim /etc/sysctl.conf 
    将其中的net.ipv4.ip_forward=1
    因为这里用的是将虚拟机作为路由器,所以需要开启路由转发功能

CentOS 6 配置静态IP及路由

step2:sysctl -p 
    重新加载配置文件,使其开启路由转发功能
step3:写入路由策略
    例:route add -net 2.2.2.0/24 gw 2.2.2.253

CentOS 6 配置静态IP及路由

step4:关闭防火墙
    iptables -F

三.模拟两台pc通过四个路由通信

模拟图:
CentOS 6 配置静态IP及路由

分析:

step1:建立两个pc 配置静态ip
step2:建立四个路由(由虚拟机代替,添加两个网卡),配置其静态ip
step3:配置完后,添加路由策略

step1:以一台pc举例,pc2同样的原理

vim /etc/udev/rules.d/70-persistent-net.rules
vim /etc/sysconfig/network-sripts/ifchg-eth*

CentOS 6 配置静态IP及路由
step2:配置四个路由

vim /etc/udev/rules.d/70-persistent-net.rules
vim /etc/sysconfig/network-sripts/ifchg-eth*

CentOS 6 配置静态IP及路由

step3:添加路由策略

route1:
route add -net 1.1.1.0/24 gw2.2.2.254
route add -net 3.3.3.0/24 gw3.3.3.252
route add -net 4.4.4.0/24 gw3.3.3.252
route add -net 5.5.5.0/24 gw3.3.3.252

CentOS 6 配置静态IP及路由

route 2
route add -net 2.2.2.0/24 gw 2.2.2.254
route add -net 3.3.3.0/24 gw 3.3.3.252
route add -net 4.4.4.0/24 gw 3.3.3.252
route add -net 5.5.5.0/24 gw 3.3.3.252

CentOS 6 配置静态IP及路由

route 3
route add -net 1.1.1.0/24 gw 3.3.3.253
route add -net 2.2.2.0/24 gw 3.3.3.253
route add -net 4.4.4.0/24 gw 4.4.4.251
route add -net 5.5.5.0/24 gw 4.4.4.251

CentOS 6 配置静态IP及路由

rotute 4
route add -net 1.1.1.0/24 gw 4.4.4.252
route add -net 2.2.2.0/24 gw 4.4.4.252
route add -net 3.3.3.0/24 gw 4.4.4.252
route add -net 5.5.5.0/24 gw 5.5.5.251

CentOS 6 配置静态IP及路由

pc1
route add default gw 1.1.1.254

CentOS 6 配置静态IP及路由

pc 2
route add default gw 5.5.5.251

CentOS 6 配置静态IP及路由

step4:测试成功:
CentOS 6 配置静态IP及路由
CentOS 6 配置静态IP及路由

转载于:https://blog.51cto.com/13572413/2084683

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值