本站内容有下面分类知识,欢迎您的到来^_^

shell相关:指令篇 基础篇 脚本欣赏 编程实例 shell问问 shell视频教程 技巧篇 水平测试 E文资料 vi编辑器 高级Bash脚本编程指南
其他:mysql perl c语言

设soyo123为首页 收藏本站
当前位置:|主页>shell脚本欣赏>

切换网卡地址的shell

百度收藏 QQ搜藏

用vmware经常在不同网络中改配置,很麻烦。
比如我在家用adsl或者有时是dhcp获取地址,这个时候虚拟机就得用hostonly共享一块网卡上网,在公司我可直接设置为bridged模式。为了一劳永逸,更改如下:

1.在vmware菜单的vm-settings增加一块网卡eth1,并-设置为bridged
2.eth0设置为hostonly
3.设置本地真实网卡允许eth0连接共享
4.在redhat中增加如下脚本,这样可实现hostonly模式和bridged的快速切换

当然你还可更改脚本让它智能判断当前网络处于什么情况自己切换。

[root@rh9bk root]# cat swnet.sh
if [ $# -eq 0 ];then
echo "Usage $0 hostonly|bridg"
exit 1
fi

case "$1" in
hostonly)
ifconfig eth1 down
ifconfig eth0 192.168.0.2 up
route add default gw 192.168.0.1 #我的vmnet01网卡地址
echo "ok! the network set hostonly..."
;;
bridg)
ifconfig eth0 down
ifconfig eth1 192.168.20.200 up
route add default gw 192.168.20.1 #公司的网关地址
echo "ok! the network set bridged.."
;;
esac


上一篇:Shell写的贪吃蛇游戏 下一篇:为方便在Ubuntu下使用Drcom而编的SHELL
power by soyo123 2007-2008