(1) The idea of modifying dynamic IP to static IP
① back up the Ifcfg-eth0 file before modifying IP
② Enter the NIC configuration directory/etc/sysconfig/network-scripts/ifcfg-eth0
③ modifying Bootproto=static
④ modifying Onboot=yes
⑤ Configuring a static IP address ipaddr
⑥ Configuring DNS NETMASK
⑦ Configuring the Gateway Gatway
⑧ Restart the NIC authentication configuration, verify the configuration Results service network restart
(2) The idea of modifying static IP to other static IP
☆ First determine whether it is static IP grep "DHCP"/etc/sysconfig/network-scripts/ifcfg-eth0/
☆
If[$? -ne 0]; Then
Sed-i ' s/^ipaddr/#IPADDR/g ' ifcfg-eth0
Read-p "Please Enter IP:" ipaddr
echo "ipaddr=" $IPADDR ">>/etc/sysconfig/network-scripts/
Fi
☆ Restart NIC Verify configuration results service Network restart
code example:
#!/bin/bash #2017年12月17日19:34:40 #by author Daqi #change IP Shell Net_file= "/etc/sysconfig/network-scripts" Net_dir= "Ifcfg-eth0" CD $NET _file/ #change IP static for static: grep "DHCP" $NET _file/$NET _dir If [$?-ne 0];then Sed-i s/^ipaddr/#IPADDR/g $NET _dir Read-p "Please enter IP address,example 192.168.0.11 IP": ipaddr echo "Ipaddr= $IPADDR" >> $NET _file/$NET _dir Service Network restart Else #change IP dhcp for static Sed-i s/dhcp/static/g $NET _dir Sed-i s/onboot=no/onboot=yes/g $NET _dir Read-p "Please enter IP address,example 192.168.0.11 IP": ipaddr cat>> $NET _file/$NET _dir <<eof Ipaddr= $IPADDR netmask=255.255.255.0 gatway=192.168.2.1 Eof Service Network restart Fi |
Use Shell to modify dynamic IP to static IP, static IP to other static IP