Pages

Friday, December 18, 2015

Working with Network on CentOS/RHEL 07 - Part 12

Home

Configure DHCP IP address using configuration files

- We will simply see a basic example of changing IP address to DHCP mode using “ifcfg-*” files present in network-script directory of NetworkManager Daemon service.
- First check for the existing content in the configuration file

[root@myserver2 network-scripts]# cat ifcfg-Wired_connection_3
TYPE=Ethernet
BOOTPROTO=none
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=no
NAME=Wired_connection_3
UUID=46a40de1-e50a-4b1f-90e4-413cc53a34e9
DEVICE=enp0s9
ONBOOT=yes
HWADDR=08:00:27:B6:50:F3
IPADDR=192.168.248.100
PREFIX=24

[root@myserver2 network-scripts]# ip a sh dev enp0s9
4: enp0s9: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 08:00:27:b6:50:f3 brd ff:ff:ff:ff:ff:ff
    inet 192.168.248.100/24 brd 192.168.248.255 scope global enp0s9
       valid_lft forever preferred_lft forever
    inet6 fe80::a00:27ff:feb6:50f3/64 scope link
       valid_lft forever preferred_lft forever

- Now time to get some changes done to the configuration file, in our example we will change the IP address so new IP

[root@myserver2 network-scripts]# vi ifcfg-Wired_connection_3
[root@myserver2 network-scripts]# cat ifcfg-Wired_connection_3
TYPE=Ethernet
BOOTPROTO=dhcp
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=no
NAME=Wired_connection_3
UUID=46a40de1-e50a-4b1f-90e4-413cc53a34e9
DEVICE=enp0s9
ONBOOT=yes
HWADDR=08:00:27:B6:50:F3
#IPADDR=192.168.248.100
#PREFIX=24

- Post changes in the configuration file, to get those reflected get the interface down and up using ifdown and ifup commands.

[root@myserver2 network-scripts]# ifdown enp0s9
[root@myserver2 network-scripts]# nmcli dev status
DEVICE   TYPE      STATE         CONNECTION
enp0s3   ethernet  connected     Wired_connection_1
enp0s8   ethernet  connected     Wired_connection_2
enp0s10  ethernet  disconnected  --
enp0s9   ethernet  disconnected  --
lo       loopback  unmanaged     --
[root@myserver2 network-scripts]# ifup enp0s9
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/7)
[root@myserver2 network-scripts]# nmcli dev status
DEVICE   TYPE      STATE         CONNECTION
enp0s3   ethernet  connected     Wired_connection_1
enp0s8   ethernet  connected     Wired_connection_2
enp0s9   ethernet  connected     Wired_connection_3
enp0s10  ethernet  disconnected  --
lo       loopback  unmanaged     --
[root@myserver2 network-scripts]# ip a sh dev enp0s9
4: enp0s9: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 08:00:27:b6:50:f3 brd ff:ff:ff:ff:ff:ff
    inet 192.168.248.203/24 brd 192.168.248.255 scope global dynamic enp0s9
       valid_lft 1174sec preferred_lft 1174sec
    inet6 fe80::a00:27ff:feb6:50f3/64 scope link
       valid_lft forever preferred_lft forever

- Permanent changes has been made successfully to the interface using configuration files.

No comments:

Post a Comment