Linux教程

Linux配置IP 的shell脚本

本文主要是介绍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 '脚本退出!'

这篇关于Linux配置IP 的shell脚本的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!