CentOS 7 set static ip address


  1. Set IP address in /etc/sysconfig/network-scripts/ifcfg-eth0
    # find / -name ifcfg-eth0   (find the file)
    # vi /etc/sysconfig/network-scripts/ifcfg-eth0
    
    TYPE=Ethernet
    DEVICE=eth0
    HWADDR=00:15:5D:8B:23:20
    UUID=876fff11-041 ...
    ONBOOT=yes
    NM_CONTROLLED=no
    BOOTPROTO=static
    IPADDR=192.168.1.59
    NETMASK=255.255.255.0
    GATEWAY=192.168.1.1
    DNS1=8.8.8.8
    DNS2=8.8.4.4
    
    Save and quit:  type :wq 
    
    Now restart the network services.
    [root@hostname~]# service network restart
    
    Verify the IP address
    [root@hostname~]# ip addr
    

  2. Find public IP addresses of the server
    # curl ifconfig.me
    
    or
    # curl ident.me
    # curl -4 icanhazip.com
    # curl ipinfo.io/ip
    # curl bot.whatismyipaddress.com
    # curl ipecho.net/plain