July 09, 2016

How to change Linux IP address(static, dynamic)

❑ Legacy(Ubuntu)

check ip address in Ubuntu

1. ifconfig : Check interface to convert IP address


interface down in Ubuntu

2. ifdown : Shut down the interface


interface show in Ubuntu

3. vi /etc/network/interfaces : Change the interface information(static or dynamic)


interface up in Ubuntu

4. ifup : No shutdown the interface






❑ Legacy(CentOS 7)

1. # vi /etc/sysconfig/network-scripts/ifcfg-xx

2.1 Static(Refer to the data below)
BOOTPROTO="static"
IPADDR="192.168.100.70"
GATEWAY="192.168.100.1"
NETMASK="255.255.255.0"

2.2 Dynamic(Refer to the data below)
BOOTPROTO="dhcp"

3. # service network restart




❑ NetworkManager(CentOS 7)

1.1 Static
# nmcli connection add con-name [Connection name] type ethernet ifname [Interface name] ip4 "192.168.100.50/24" gw4 "192.168.100.2"
# nmcli connection reload
# nmcli connection up [Connection name] : [Interface name] and [Connection name] are connected.
* You can input "nmcli connection show [Connection name]" to see "ipv4.method: manual".

1.2 Dinamic
# nmcli connection add con-name [Connection name] type ethernet ifname [Interface name] autoconnect yes
# nmcli connection reload
# nmcli connection up [Connection name] : [Interface name] and [Connection name] are connected.
* You can input "nmcli connection show [Connection name]" to see "ipv4.method : auto".




❑ NetworkManager(Static ↔ Dynamic)(CentOS 7)

1. Static → Dynamic
# nmcli connection modify [Connection name] connection.id [Connection name to be changed] ipv4.addresses "" ipv4.gateway "" ipv4.method auto
# nmcli connection reload


2. Dynamic → Static
# nmcli connection modify [Connection name] connection.id [Connection name to be changed] ipv4.addresses "192.168.100.100/24" ipv4.gateway "192.168.100.2" ipv4.method manual ipv4.dns "8.8.8.8"
# nmcli connection reload


Check environment
O      S CentOS 7.4.1708(64bit) CPU Intel i7-4710MQ 2.50GHz
SHELL GNU bash (4.3.46(2)) RAM 1 GB