以下操作在cent os上进行
1.在系统中创建set-ip-tool命令要求如下
当在系统中执行set-ip-tool 172.25.254.X 后
*)会自动显示ifconfig命令的输出
*)系统ip被设定为:172.25.254.X
*)系统网关被设定为:172.25.254.250
*)系统dns被设定为:172.25.254.250
最后结果为
set-ip-tool.sh的代码为
#!/bin/bash
echo "set ip as $1"
nmcli connection modify System\ eth0 ipv4.addresses $1>/dev/null
echo "set gateway 172.25.254.250"
route add default gw 172.25.254.250 &>/dev/null
echo "set dns 172.25.254.250"
nmcli connection modify System\ etho ipv4.dns 172.25.254.250 &>/dev/null
systemctl restart network &>/dev/null
ifconfig