I have a server running Centos 7 which needs to be rebooted to upgrade some software.

Some of the physical NICs have around 5-10 VLAN interfaces each. They're subject to change on a weekly/monthly basis so storing the details in /etc/sysconfig/network-scripts to persist across reboots isn't practical.

Is there an simple way to take a snapshot of the current networking stack and restore after the reboot? Similar to the way you can save/restore iptables rules?

I've found several references to the system-config-network-cmd but I'm wary of using this tool in the event it overwrites the static configs for the physical interfaces we do have in /etc/sysconfig/network-scripts


  • Wouldn't a simple shell script - started with systemd - make the job ? This would run the ip / route commands you need to di your setup. – tonioc Mar 28 '18 at 14:30
  • Yes probably. It's what I'm planning on doing next if there's no better option available. – popcornuk Mar 28 '18 at 14:37

Iptables is the easy part of your ask.

iptables-save can be used to save the current iptables rules, which can then be read back in with iptables-restore.

# backup current iptables rules
iptables-save > /root/iptables-$(date +%F).save

# restore a previous set of iptables-rules
iptables-restore < /root/iptables-<date of file to restore>.save

For the network part of your task, If you're not using the "Network Manager" service, which many people don't on servers, the system-config-network-cmd or later replacements like nmtui|nmcli won't do much.

Initually, you'll have to script your own solution, which will look something like capturing the output of ip addr show, and parsing it to create an ip batch file (see: https://support.cumulusnetworks.com/hc/en-us/articles/202395708-Bringing-up-Large-Networks-Using-ip-batch for useful info on that), and then replaying that batch file via ip --batch <batchfile>, adjusted for your level of detail. Do you need MACs to be the same? other device options? any specific vlans? or is it just simply IP addresses all on the same subnet? Oh, and you may want to capture ip route show, too, if you have any ephemeral routes configured that you'll need after the reboot.

Longer term, maybe look into using Ansible (or similar) to manage deployments of both ephemeral iptables rules, and ephemeral network interface configurations. Then you can just replay your playbook, and have everything back as it needs to be.

  • 1
    Hi Tim. Thanks for the quick answer. I've already got iptables covered using save & restore command. I'm starting off a script for the network interfaces now. Your link looks promising. And yes, as well as the IP's I need the associated VLAN interface it's attached to and a list of all the static routes to be brought back up. It's giving me an excuse to do some scripting anyway. I've not written anything for a few months (shocking I know!). Thanks. – popcornuk Mar 28 '18 at 14:55

Firstly, you must be ensure that NetworkManager has installed and nmcli command exist.

After this, show your current network connections via nmcli:

# nmcli c
NAME                UUID                                  TYPE            DEVICE
enp0s3              346f92f2-e6b5-4464-b424-4083fb09e6ae  802-3-ethernet  enp0s3
enp0s8              537dd740-423a-42ab-8e62-d49a0e91de00  802-3-ethernet  enp0s8
enp0s8.10           1db1ea0f-f67e-4777-bd58-e4c6d36a8520  vlan            enp0s8.10
enp0s9              410c1405-b2fa-4182-900b-51defe29c681  802-3-ethernet  enp0s9

Interface enp0s8.10 was not added me over NetworkManager. I've added it over vconfig, ip l up and ip a.

Interface must be up and IP address assigned! If interface will not be UP or doesn't has assigned IP then NetworkManager will show it as unmanaged.

After this, you can call nmcli to edit your active connections:

# nmcli connection edit enp0s8.10

===| nmcli interactive connection editor |===

Editing existing 'vlan' connection: 'enp0s8.10'

Type 'help' or '?' for available commands.
Type 'describe [<setting>.<prop>]' for detailed property description.

You may edit the following settings: connection, 802-3-ethernet (ethernet), vlan, ipv4, ipv6, proxy
nmcli> help
---[ Main menu ]---
goto     [<setting> | <prop>]        :: go to a setting or property
remove   <setting>[.<prop>] | <prop> :: remove setting or reset property value
set      [<setting>.<prop> <value>]  :: set property value
describe [<setting>.<prop>]          :: describe property
print    [all | <setting>[.<prop>]]  :: print the connection
verify   [all | fix]                 :: verify the connection
save     [persistent|temporary]      :: save the connection
activate [<ifname>] [/<ap>|<nsp>]    :: activate the connection
back                                 :: go one level up (back)
help/?   [<command>]                 :: print this help
nmcli    <conf-option> <value>       :: nmcli configuration
quit                                 :: exit nmcli
nmcli> save
Connection 'enp0s8.10' (1db1ea0f-f67e-4777-bd58-e4c6d36a8520) successfully updated.
nmcli> quit

After this steps you will see your configuration file for interface in /etc/sysconfig/network-scripts in file ifcfg-enp0s8.10 (as in my case).

Of cause you should go through all your interfaces.


To save the configuration with system-config-network-cmd (as root):

system-config-network-cmd -e > /tmp/network-configuration.txt

To restore:

system-config-network-cmd -i -c -f /tmp/network-configuration.txt

-i = import
-c = clear the existing configuration prior to importing
-f = file name

If that fails I would recommend a script that would copy the configurations out of a directory with the interface configuration.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.