Bug 77020 - RFE: systemd-networkd: changing the ip in a .network unit and restarting the networkd service should configure the interface
Summary: RFE: systemd-networkd: changing the ip in a .network unit and restarting the ...
Status: RESOLVED NOTABUG
Alias: None
Product: systemd
Classification: Unclassified
Component: general (show other bugs)
Version: unspecified
Hardware: x86-64 (AMD64) Linux (All)
: medium normal
Assignee: Tom Gundersen
QA Contact: systemd-bugs
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-04-03 17:47 UTC by Brian "Redbeard" Harrington
Modified: 2015-02-06 12:33 UTC (History)
2 users (show)

See Also:
i915 platform:
i915 features:


Attachments

Description Brian "Redbeard" Harrington 2014-04-03 17:47:30 UTC
Below you can see the process of setting and then changing an IP address through a systemd network unit.  At the moment the IP address can be set, but changing the address subsequently does not work.  This wasn't the expected behavior.  Is this the desired workflow?  If so this should be documented.   


# Display automatically configured DHCP address:
core@localhost /etc/systemd/network $ ifconfig ens3
ens3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.122.101  netmask 255.255.255.0  broadcast 192.168.122.255
        inet6 fe80::5054:ff:fe95:b19f  prefixlen 64  scopeid 0x20<link>
        ether 52:54:00:95:b1:9f  txqueuelen 1000  (Ethernet)
        RX packets 1147  bytes 104127 (101.6 KiB)
        RX errors 0  dropped 102  overruns 0  frame 0
        TX packets 641  bytes 97180 (94.9 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

# Change configuration of the network and set a static IP:
core@localhost /etc/systemd/network $ cat /etc/systemd/network/10-static.network 
[Match]
Name=ens3

[Network]
Address=192.168.122.75/24
Gateway=192.168.122.1

# Apply the changes to the interface
core@localhost /etc/systemd/network $ sudo systemctl restart systemd-networkd.service

# Lose the connection because the IP changed
Connection to 192.168.122.101 closed.
[bharrington@leviathan-alticon-net ~]$ ssh core@192.168.122.75
Warning: Permanently added '192.168.122.75' (RSA) to the list of known hosts.
Warning: Permanently added '192.168.122.75' (RSA) to the list of known hosts.
   ______                ____  _____
  / ____/___  ________  / __ \/ ___/
 / /   / __ \/ ___/ _ \/ / / /\__ \
/ /___/ /_/ / /  /  __/ /_/ /___/ /
\____/\____/_/   \___/\____//____/

# Change the IP in the systemd unit
core@localhost ~ $ sudo sed -i 's/75/80/g' /etc/systemd/network/10-static.network 

# Display the change to confirm
core@localhost ~ $ cat /etc/systemd/network/10-static.network
[Match]
Name=ens3

[Network]
Address=192.168.122.80/24
Gateway=192.168.122.1

# Apply the change
core@localhost ~ $ sudo systemctl restart systemd-networkd.service

# Display that the change was not applied
core@localhost ~ $ ifconfig ens3
ens3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.122.75  netmask 255.255.255.0  broadcast 192.168.122.255
        inet6 fe80::5054:ff:fe95:b19f  prefixlen 64  scopeid 0x20<link>
        ether 52:54:00:95:b1:9f  txqueuelen 1000  (Ethernet)
        RX packets 1540  bytes 143430 (140.0 KiB)
        RX errors 0  dropped 136  overruns 0  frame 0
        TX packets 872  bytes 129409 (126.3 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

# Show the logs to display the HUP of networkd
core@localhost ~ $ journalctl -xn -u systemd-networkd.service
-- Logs begin at Thu 2014-04-03 17:36:24 UTC, end at Thu 2014-04-03 17:40:49 UTC. --
Apr 03 17:40:02 localhost systemd-networkd[2984]: lo: carrier on
Apr 03 17:40:02 localhost systemd-networkd[2984]: ens3: link configured
Apr 03 17:40:49 localhost systemd[1]: Stopping Network Service...
Apr 03 17:40:49 localhost systemd[1]: Starting Network Service...
Apr 03 17:40:49 localhost systemd-networkd[3001]: ens3: link is up
Apr 03 17:40:49 localhost systemd-networkd[3001]: ens3: carrier on
Apr 03 17:40:49 localhost systemd-networkd[3001]: lo: link is up
Apr 03 17:40:49 localhost systemd-networkd[3001]: lo: carrier on
Apr 03 17:40:49 localhost systemd-networkd[3001]: ens3: link configured
Apr 03 17:40:49 localhost systemd[1]: Started Network Service.
Comment 1 Brian "Redbeard" Harrington 2014-04-03 18:31:17 UTC
Note:  Other changes are propagated.  e.g. You'll notice that the static config defined below didn't include a:

[Network]
DNS=

Entry.  When the restart occurred this blew away the DHCP configured resolv.conf.  Creating this entry and restarting systemd-networkd.service again properly populated the new resolv.conf entry.
Comment 2 Tom Gundersen 2014-06-19 16:13:28 UTC
At the moment, we really only support static setups and dynamic reconfiguration at run-time needs more work.
Comment 3 Tom Gundersen 2014-06-30 17:02:44 UTC
Just realised: could this be a limitation of "ifconfig"? I.e., the situation is currently that networkd will only add adresses, and never tear them down, so in your situation you should actually end up with both the old and the new address (until you reboot, at which point you'll only have the new one). I'm not sure if ifconfig will print all your addresses though... Could you try "ip address show dev ens3"?
Comment 4 Philip Tolton 2014-11-19 21:54:22 UTC
Tom Gundersen, you are correct. "ip address show dev wlan0" in my case shows both ips.
Comment 5 Tom Gundersen 2015-02-06 12:33:17 UTC
Restarting networkd adds cofig, but does not remove it. This is currently as expected. The problem observed here is ifconfig not able to show all ip addresses (don't use ifconfig, it has lots of issues).


Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.