永久改动redhat的default route
1,能够用route命令暂时改动:
route add default gw <gateway ip>
2, 通过改动/etc/sysconfig/network 文件永久改动:
脚本:
#!/bin/sh
#configure default gw
# $1 is ip of gateway
defgw=$1
sed -i "s/NETWORKING.*/NETWORKING=yes/" /etc/sysconfig/network
sed -i "s/HOSTNAME.*/HOSTNAME=`hostname`/" /etc/sysconfig/network
echo "GATEWAY=$defgw" >> /etc/sysconfig/network
service network restart
事实上终于的/etc/sysconfig/network的格式是:
~]# cat /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=c902f02x44
GATEWAY=60.0.0.202
然后重新启动network服务:service network restart