Ask Your Question
0

DHCP and static IP simultaneously with NetworkManager

asked 2016-08-01 01:43:54 -0500

Clayton Louden gravatar image

Hi,

I've got a NIC that gets one address via dhcp and another one statically assigned. This is done with Fedora's legacy network service (systemctl start network) and these config files

/etc/sysconfig/network-scripts/ifcfg-enp0s25:

HWADDR=XX:XX:XX:XX:XX:XX
TYPE=Ethernet
BOOTPROTO=dhcp
DEFROUTE=yes
PEERDNS=yes
PEERROUTES=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes
IPV6_FAILURE_FATAL=no
NAME=enp0s25
ONBOOT=yes

and

/etc/sysconfig/network-scripts/ifcfg-enp0s25:0:

TYPE=Ethernet
BOOTPROTO=none
IPADDR=192.168.99.4
PREFIX=24
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=no
NAME=static-ip
ONBOOT=yes

which works just fine:

# ip addr show
...
2: enp0s25: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether xx:xx:xx:xx:xx:xx brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.68/24 brd 192.168.1.255 scope global dynamic enp0s25
       valid_lft 6887sec preferred_lft 6887sec
    inet 192.168.99.4/24 brd 192.168.99.255 scope global enp0s25:0
       valid_lft forever preferred_lft forever
    inet6 fe80::2ad2:44ff:fe7d:c66d/64 scope link 
       valid_lft forever preferred_lft forever

How can I achieve the same with NetworkManager? If I just disable the legacy network service and start NetworkManager with the same set of config files, I'll just get an IP address from the dhcp server (it seems the ifcfg-enp0s25:0 file is simply ignored)

Any pointers are greatly appreciated!

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2016-08-02 09:50:50 -0500

updated 2016-08-02 09:52:19 -0500

This should be easily accomplished with NetworkManager; you simply need to identify the two connection profiles at play here (nmcli c should provide a list) and then modify the configuration option for the profile you need to make use of a DHCP address.

So, say the connection profile name you want to configure for DHCP is "eno2":

[bash]$ sudo nmcli c edit eno2
nmcli> print ipv4   #this lists your ipv4 settings for the connection profile
nmcli> set ipv4.method auto
nmcli> save
nmcli> quit
[bash]$ sudo nmcli c reload eno2

If the reload command doesn't do it, you can try nmcli c down eno2 followed by nmcli c up eno2 and then use ip addr to see if you've acquired the DHCP address as you desire.

Let me know how it goes!

edit flag offensive delete link more

Question Tools

Stats

Asked: 2016-08-01 01:43:54 -0500

Seen: 1,399 times

Last updated: Aug 02 '16