Linux配置IP 的shell脚本

ption=100
#初始化一个条件


echo -e "\n"
echo '--------------- yy Options for commands to excute yy -------------'
echo ' 0. 退出脚本'
echo ' 1. 配置动态ip'
echo ' 2. 配置静态ip'
echo ' 3. 删除指定连接'
echo ' 4. 显示所有网络连接'
echo ' 5. 关闭指定网络连接'
echo ' 6. 开启指定网络连接'
echo ' 7. 修改指定连接的ip地址'
echo ' 8. 修改指定连接的连接方式'
echo ' 9. 连接到eth0'
echo ' 10. 断开eth0设备连接'
echo ' 11. 显示所有连接设备'
echo ' 12. 显示所有设备状态'
echo '-----------------------------------------------------------------'
until [ $option == 0 ]
do
echo -e "\n"
read -p "PLease input your option (0 to quit) : " option
echo 'your option is: ' $option
if [ $option -gt 0 ]
then
echo 'The output: '
fi
echo -e "\n"
case $option in
1)
read -p 'please input your con-name: ' name
`nmcli connection add type ethernet con-name $name ifname eth0 autoconnect yes`
;;
2)
read -p 'please input your con-name and ipv4: ' name ip
`nmcli connection add type ethernet con-name $name ifname eth0 ip4 $ip/24`
;;
3)
read -p 'please input your con-name: ' name
nmcli connection delete $name
;;
4)
nmcli connection show
;;
5)
read -p 'please input your con-name: ' name
nmcli connection down $name
;;
6)
read -p 'please input your con-name: ' name
nmcli connection up $name
;;
7)
read -p 'please input your con-name and ipv4: ' name ip
`nmcli connection modify $name ipv4.addresses $ip/24`
;;
8)
read -p "Please input your con-name and method to modify: " name method
nmcli connection modify $name ipv4.method $method
;;
9)
nmcli device connect eth0
;;
10)
nmcli device disconnect eht0
;;
11)
nmcli device show
;;
12)
nmcli device status
;;

esac

systemctl restart network
done
echo '脚本退出!'

上一篇:Java学习笔记之——线程的生命周期、线程同步


下一篇:python爬取游戏新闻和视频