首先,先了解传统的网络配置命令:
1. 使用ifconfig命令配置并查看网络接口情况
示例1: 配置eth0的IP,同时激活设备:
# ifconfig eth0 192.168.4.1 netmask 255.255.255.0 up
示例2: 配置eth0别名设备 eth0:1 的IP,并添加路由
# ifconfig eth0:1 192.168.4.2
# route add –host 192.168.4.2 dev eth0:1
示例3:激活(禁用)设备
# ifconfig eth0:1 up(down)
示例4:查看所有(指定)网络接口配置
# ifconfig (eth0)
2. 使用route 命令配置路由表
示例1:添加到主机路由
# route add –host 192.168.4.2 dev eth0:1
# route add –host 192.168.4.1 gw 192.168.4.250
示例2:添加到网络的路由
# route add –net IP netmask MASK eth0
# route add –net IP netmask MASK gw IP
# route add –net IP/24 eth1
示例3:添加默认网关
# route add default gw IP
示例4:删除路由
# route del –host 192.168.4.1 dev eth0:1
示例5:查看路由信息
# route 或 route -n (-n 表示不解析名字,列出速度会比route 快)
实践脚本
#! /bin/sh
route add -host 192.168.0.12 dev eth0
route add -host 192.168.1.137 dev eth0
route add -host 192.168.0.192 dev eth1
route del default
route del default
route del -net 192.168.0.0 netmask 255.255.0.0 eth0
route del -net 192.168.0.0 netmask 255.255.0.0 eth1
ctdb集群的samba server的route控制脚本
#! /bin/sh
route del default
route del default
route del -net 192.168.0.0 netmask 255.255.0.0 eth0
route del -net 192.168.0.0 netmask 255.255.0.0 eth1
route add -net 192.168.0.0 netmask 255.255.0.0 eth0
route add -net 192.168.1.0 netmask 255.255.255.0 eth1
route add default gw 192.168.1.1
210的route表
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.0.12 * 255.255.255.255 UH 0 0 0 eth0
192.168.0.22 * 255.255.255.255 UH 0 0 0 eth0
192.168.0.111 * 255.255.255.255 UH 0 0 0 eth0
192.168.0.112 * 255.255.255.255 UH 0 0 0 eth0
192.168.0.113 * 255.255.255.255 UH 0 0 0 eth1
192.168.0.114 * 255.255.255.255 UH 0 0 0 eth1
192.168.1.0 * 255.255.255.0 U 0 0 0 eth1