在主机系统上创建set-ip命令要求如下:
*)会自动显示ifconfig命令的输出
*)系统ip被设定为:172.25.254.X
*)系统网关被设定为:172.25.254.77
*)系统dns被设定为:172.25.254.77
*)可以多次更换ip
解答:
在/bin下编辑命令
[root@localhost ~]# vim /bin/set-ip
cd /etc/sysconfig/network-scripts
rm -fr ifcfg-eth0
cat >ifcfg-eth0 <<Q
DEVICE=eth0
BOOTPROTO=none
ONBOOT=yes
NAME=eth0
IPADDR=172.25.254.$1
PREFIX=24
GATEWAY=172.25.254.77
DNS=172.25.254.77
Q
systemctl restart network
ifconfig
测试:
运行之前要改写set-ip命令文件的权限
chmod 777 /bin/set-ip
命令编写成功。