linux定时切换无规则ip,linux自动切换Ip

ubuntu:

#!/bin/bash

PS3="Select your network:"

echo "auto eth0" > /etc/network/interfaces

select choice in "home(dhcp)" "company(static)"

do

case "$REPLY" in

1)

echo "iface eth0 inet dhcp" >> /etc/network/interfaces

break;;

2)

echo "iface eth0 inet static" >> /etc/network/interfaces

echo "address 192.168.10.160" >> /etc/network/interfaces

echo "netmask 255.255.255.0" >> /etc/network/interfaces

echo "gateway 192.168.10.2" >> /etc/network/interfaces

break;;

*)

echo -e "$REPLY is not a valid choice.Try again\n" 1>&2

REPLY=

;;

esac

done

echo "auto lo" >> /etc/network/interfaces

echo "iface lo inet loopback" >> /etc/network/interfaces

/etc/init.d/networking restart

redhat,fedora,centos的:

#!/bin/bash

echo 'DEVICE=eth0' > /etc/sysconfig/network-scripts/ifcfg-eth0

echo 'ONBOOT=yes' >> /etc/sysconfig/network-scripts/ifcfg-eth0

echo 'TYPE=Ethernet' >> /etc/sysconfig/network-scripts/ifcfg-eth0

echo 'BOOTPROTO=static' >> /etc/sysconfig/network-scripts/ifcfg-eth0

if [ $1 = "home" ] ; then

echo 'IPADDR=192.168.10.160' >> /etc/sysconfig/network-scripts/ifcfg-eth0

echo 'NETMASK=255.255.255.0' >> /etc/sysconfig/network-scripts/ifcfg-eth0

echo 'GATEWAY=192.168.10.2' >> /etc/sysconfig/network-scripts/ifcfg-eth0

echo 'nameserver 202.96.69.38' > /etc/resolv.conf

else

echo 'IPADDR=10.0.0.2' >> /etc/sysconfig/network-scripts/ifcfg-eth0

echo 'NETMASK=255.0.0.0' >> /etc/sysconfig/network-scripts/ifcfg-eth0

echo 'GATEWAY=10.0.0.1' >> /etc/sysconfig/network-scripts/ifcfg-eth0

echo 'nameserver 10.0.0.100' > /etc/resolv.conf

fi;

service network restart

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值