服务器ip配置 & 策略路由配置

添加路由命令:(临时)
ip route add 172.17.0.0/20 via 172.17.0.1 dev em2
ip route add 192.168.13.0/24 via 192.168.1.254 dev eth0
删除路由:
ip route del 192.168.13.0/24



#!/system/bin/sh
echo "################ sleep to wait net done! 10 seconds!"
sleep 10
echo "start add route"
busybox route add -net 192.168.12.0/24 gw 192.168.1.254


#!/system/bin/sh
sleep 10
busybox route add -net default gw 192.168.1.254




永久静态路由需要写到 /etc/sysconfig/network-scripts/route-interface 文件中,比如添加两条静态路由:

[root@centos7 ~]# vi /etc/sysconfig/network-scripts/route-enp0s3
10.15.150.0/24 via 192.168.150.253 dev enp0s3
10.25.250.0/24 via 192.168.150.253 dev enp0s3

添加完毕后重启网络服务生效
service  network restart


centos7配置服务器网络:
/etc/sysconfig/network-scirpts/ifcfg-em1

参考范例
=====动态ip========================================================
[root@203_1 ~]# cat /etc/sysconfig/network-scripts/ifcfg-eno16777984
TYPE=Ethernet
BOOTPROTO=dhcp
DEFROUTE=yes
PEERDNS=yes
PEERROUTES=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes
IPV6_FAILURE_FATAL=no
NAME=eno16777984
UUID=fb5a7f96-ec24-4663-b852-0df698fa76e5
DEVICE=eno16777984
ONBOOT=no

=====静态ip=========================================================
[root@master191 network-scripts]# cat ifcfg-eno16777984
TYPE=Ethernet
BOOTPROTO=static
IPADDR=192.168.1.191
NETMASK=255.255.255.0
GATEWAY=192.168.1.254
NM_CONTROLLED=no
DEFROUTE=yes
PEERDNS=yes
PEERROUTES=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes
IPV6_FAILURE_FATAL=no
NAME=eno16777984
UUID=3e6ca510-7e48-48fb-a55a-3d9bb035cd46
DEVICE=eno16777984
ONBOOT=yes
ZONE=public

你可能感兴趣的:(LInux运维)