Page MenuHomeVyOS Platform

DHCP and Static IPs on Same Interface
Closed, ResolvedPublicFEATURE REQUEST

Description

In VyOS, when attempting to assign both a static and DHCP address to an interface, the following is received:

vyos@cr01a-vyos# set interfaces bonding bond0 vif 20 address 192.168.100.2/24
[edit]
vyos@cr01a-vyos# show interfaces bonding bond0 vif 20
 address dhcp
+address 192.168.100.2/24
 description "DL: L::cr01a-vyos.int bond0.20 | R::ir01.int Po5.20"
 ipv6 {
     dup-addr-detect-transmits 0
 }
 mac 52:54:00:bb:99:6a
 mtu 1500
[edit]
vyos@cr01a-vyos# commit
[ interfaces bonding bond0 vif 20 ]


[ interfaces bonding bond0 vif 20 address 192.168.100.2/24 ]


[ interfaces bonding bond0 ]
Can't configure both static IPv4 and DHCP address on the same interface

[[interfaces bonding bond0]] failed
Commit failed

From a technical standpoint, this is entirely possible:

vyos@cr01a-vyos# sudo ip a add 192.168.100.2/24 dev bond0.20 
[edit]
vyos@cr01a-vyos# ping 192.168.100.1
PING 192.168.100.1 (192.168.100.1) 56(84) bytes of data.
64 bytes from 192.168.100.1: icmp_seq=1 ttl=64 time=2.64 ms
64 bytes from 192.168.100.1: icmp_seq=2 ttl=64 time=1.62 ms
64 bytes from 192.168.100.1: icmp_seq=3 ttl=64 time=1.67 ms
64 bytes from 192.168.100.1: icmp_seq=4 ttl=64 time=1.29 ms
^C
--- 192.168.100.1 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 8ms
rtt min/avg/max/mdev = 1.286/1.802/2.638/0.506 ms
vyos@cr01a-vyos# ip a show bond0.20
7: bond0.20@bond0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
    link/ether 52:54:00:bb:99:6a brd ff:ff:ff:ff:ff:ff
    inet 1.2.3.4/18 brd 255.255.255.255 scope global dynamic bond0.20
       valid_lft 26321sec preferred_lft 26321sec
    inet 192.168.100.2/24 scope global bond0.20
       valid_lft forever preferred_lft forever
    inet6 fe80::5054:ff:febb:996a/64 scope link 
       valid_lft forever preferred_lft forever

Why is this prevented in the configuration? Can we remove the error and allow it?

Details

Version
1.3
Is it a breaking change?
Perfectly compatible
Issue type
Feature (new functionality)

Event Timeline

trae32566 updated the task description. (Show Details)
trae32566 updated the task description. (Show Details)
trae32566 edited a custom field.
trae32566 changed Version from - to 1.3.

This is a old quirk that's long known (probably was already reported) and
can be worked around by adding a pseudo-ethernet interface with the DHCP
client on it.

Apr 13, 2020 8:15:55 AM trae32566 (Trae E Santiago)
<phabricator@mg.vyos.io>:

trae32566 changed Difficulty level from Unknown (require assessment) to

Easy (less than an hour).

trae32566 changed Version from - to 1.3.

TASK DETAIL
https://phabricator.vyos.net/T2281

EMAIL PREFERENCES
https://phabricator.vyos.net/settings/panel/emailpreferences/

To: trae32566
Cc: #active_contributors, Maintainers, trae32566, teadur, jack9603301,

hard, pa4ka, jestabro, Alfa80, dongjunbo, hexes, pasik

Shouldn't it be fixed at some point though? I mean is there a reason this should stay something that has to be worked around?

erkin set Issue type to Feature (new functionality).Aug 30 2021, 7:08 AM
erkin removed a subscriber: Global Notifications.
Viacheslav subscribed.

For 1.4 it is impossible to set both dhcp + static in one commit.

set interfaces ethernet eth2 address dhcp
set interfaces ethernet eth2 address 192.0.2.4/24

vyos@r1-roll# commit
[ interfaces ethernet eth2 ]
Can't configure both static IPv4 and DHCP address on the same interface

But it is possible with 2 commits:

vyos@r1-roll# set interfaces ethernet eth2 address 192.0.2.4/24
[edit]
vyos@r1-roll# commit
vyos@r1-roll# 
vyos@r1-roll# set interfaces ethernet eth2 address dhcp
[edit]
vyos@r1-roll# commit

vyos@r1-roll# run show int ethernet 
Codes: S - State, L - Link, u - Up, D - Down, A - Admin Down
Interface        IP Address                        S/L  Description
---------        ----------                        ---  -----------
eth0             192.168.122.11/24                 u/u  
eth1             100.64.0.1/30                     u/u  
eth2             192.0.2.4/24                      u/u  
                 192.168.100.177/24                     
[edit]
vyos@r1-roll#
Viacheslav changed the task status from Open to In progress.Nov 1 2021, 1:06 PM
Viacheslav claimed this task.
Viacheslav changed the task status from In progress to Needs testing.Nov 3 2021, 5:58 PM

One issue with static + dhcp on one interface at the same time.
After renew, the static address 192.168.122.11 is disappears
To reproduce:

vyos@r11-roll:~$ show conf com | match eth0
set interfaces ethernet eth0 address '192.168.122.11/24'
set interfaces ethernet eth0 address 'dhcp'

Renew dhcp:

vyos@r11-roll:~$ renew dhcp interface eth0

Static address not in the system:

vyos@r11-roll:~$ show int
Codes: S - State, L - Link, u - Up, D - Down, A - Admin Down
Interface        IP Address                        S/L  Description
---------        ----------                        ---  -----------
eth0             192.168.122.166/24                u/u  WAN
eth1             203.0.113.1/24                    u/u  


vyos@r11-roll:~$ sudo ip -4 a show dev eth0
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    inet 192.168.122.166/24 brd 192.168.122.255 scope global dynamic eth0
       valid_lft 3233sec preferred_lft 3233sec
vyos@r11-roll:~$

https://github.com/vyos/vyos-1x/blob/5c5e283f8a964f5bbb3d838d1c0aabdee4e2032b/op-mode-definitions/dhcp.xml.in#L181

https://salsa.debian.org/dhcp-team/isc-dhcp/-/blob/debian/4.4.1-2/debian/dhclient-script.linux#L240