Is there a way to save current state of network configuration in linux into a datafile or set of ip commands like iptables-save?
Clash Royale CLAN TAG#URR8PPP
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
Let's say I ran quite a few ip commands and ended up with a required network configuration, but I didn't save the command history.
Instead of rewriting commands in a file or script again, is there a way to dump/save the state of network configuration like iptables-save or mysqldump and so, later we can restore?
I see similar thing is possible with netnsh
in windows (not sure if it's exactly the kind of solution I am looking for..havne't gone through it, but it seems like it dumps the network configuration state).
But I can't find any option in Linux (especially CentOS/RHEL)
linux centos iproute systemd-networkd
add a comment |
Let's say I ran quite a few ip commands and ended up with a required network configuration, but I didn't save the command history.
Instead of rewriting commands in a file or script again, is there a way to dump/save the state of network configuration like iptables-save or mysqldump and so, later we can restore?
I see similar thing is possible with netnsh
in windows (not sure if it's exactly the kind of solution I am looking for..havne't gone through it, but it seems like it dumps the network configuration state).
But I can't find any option in Linux (especially CentOS/RHEL)
linux centos iproute systemd-networkd
Doesn't iptables-save work at all?
– Raman Sailopal
Mar 15 at 13:07
iptables-save working for saving iptable rules. I am looking for a similar way to save network configuration. However, I can think of some reasons why it may not be possible to save network configuration entirely, as if a physical interface is missing at the time of restore, few configurations may fail.
– GP92
Mar 15 at 13:22
add a comment |
Let's say I ran quite a few ip commands and ended up with a required network configuration, but I didn't save the command history.
Instead of rewriting commands in a file or script again, is there a way to dump/save the state of network configuration like iptables-save or mysqldump and so, later we can restore?
I see similar thing is possible with netnsh
in windows (not sure if it's exactly the kind of solution I am looking for..havne't gone through it, but it seems like it dumps the network configuration state).
But I can't find any option in Linux (especially CentOS/RHEL)
linux centos iproute systemd-networkd
Let's say I ran quite a few ip commands and ended up with a required network configuration, but I didn't save the command history.
Instead of rewriting commands in a file or script again, is there a way to dump/save the state of network configuration like iptables-save or mysqldump and so, later we can restore?
I see similar thing is possible with netnsh
in windows (not sure if it's exactly the kind of solution I am looking for..havne't gone through it, but it seems like it dumps the network configuration state).
But I can't find any option in Linux (especially CentOS/RHEL)
linux centos iproute systemd-networkd
linux centos iproute systemd-networkd
asked Mar 15 at 12:58
GP92GP92
2442720
2442720
Doesn't iptables-save work at all?
– Raman Sailopal
Mar 15 at 13:07
iptables-save working for saving iptable rules. I am looking for a similar way to save network configuration. However, I can think of some reasons why it may not be possible to save network configuration entirely, as if a physical interface is missing at the time of restore, few configurations may fail.
– GP92
Mar 15 at 13:22
add a comment |
Doesn't iptables-save work at all?
– Raman Sailopal
Mar 15 at 13:07
iptables-save working for saving iptable rules. I am looking for a similar way to save network configuration. However, I can think of some reasons why it may not be possible to save network configuration entirely, as if a physical interface is missing at the time of restore, few configurations may fail.
– GP92
Mar 15 at 13:22
Doesn't iptables-save work at all?
– Raman Sailopal
Mar 15 at 13:07
Doesn't iptables-save work at all?
– Raman Sailopal
Mar 15 at 13:07
iptables-save working for saving iptable rules. I am looking for a similar way to save network configuration. However, I can think of some reasons why it may not be possible to save network configuration entirely, as if a physical interface is missing at the time of restore, few configurations may fail.
– GP92
Mar 15 at 13:22
iptables-save working for saving iptable rules. I am looking for a similar way to save network configuration. However, I can think of some reasons why it may not be possible to save network configuration entirely, as if a physical interface is missing at the time of restore, few configurations may fail.
– GP92
Mar 15 at 13:22
add a comment |
2 Answers
2
active
oldest
votes
Some support does exist for saving addresses, routes and rules, using iproute2's ip
command.
For obvious reason, this doesn't exist for links, even if one could imagine the possibility to save some virtual links, not all ("saving" a single side of a veth-pair link with its peer accross an other network namespace? not gonna happen...), or being able to save a bridge's and bridge's ports configurations including vlan etc., this doesn't appear to exist currently.
Existing commands are:
ip address save
ip address restore
ip route save
ip route restore
ip rule save
ip rule restore
The dump format is binary and the commands will refuse to save to or restore from a tty.
I suggest restoring addresses before routes (rules can be done at any order), or most saved routes won't be restored because they can't satisfy routing conditions depending on addresses. Warning: of course all flush commands below will likely disrupt network connectivity until the restore is done, so this should be avoided from remote network access (or be done in other network namespaces).
ip address save
/ip address restore
So to copy addresses from a simple network namespace
orig
's configuration having adummy0
interface (to keep the example simple) to a namespacecopy
:ip netns add orig
ip netns exec orig sh << 'EOF'
ip link add dummy0 type dummy
ip address add dev dummy0 192.0.2.2/24
ip address add dev dummy0 2001:db8:0:1::2/64
ip link set dummy0 up
ip address save > /tmp/address
EOF
ip netns add copy
ip netns exec copy sh << 'EOF'
ip link add dummy0 type dummy
ip link set dummy0 up
ip address restore < /tmp/address
ip -br address
EOFwill give for example this result:
lo DOWN
dummy0 UNKNOWN 192.0.2.2/24 2001:db8:0:1::2/64 fe80::68e3:bdff:feb0:6e85/64 fe80::e823:d1ff:fe8c:3a15/64Note: that previous automatic IPv6 link-local (
scope link
) address was also saved, and is thus restored, leading to an additional (and wrong) IPv6 link-local address, because the link/ether address (here inorig
6a:e3:bd:b0:6e:85
) on which is based the IPv6 link-local address is not saved and thus not restored (leaving here the incopy
the other random MACea:23:d1:8c:3a:15
ondummy0
). So care should actually be done to separately save and copy the MAC address of such virtual interfaces if it really matters, or prune after some addresses for physical interfaces.You should probably flush all addresses before restoring them to avoid leaving old ones if the environment wasn't a "clean slate". Contrary to routes below, I couldn't find a simple way to flush all of them in one command without having to state an interface. Using those two should be good enough:
ip address flush permanent
ip address flush temporary
On the same principle, routes and rules can be saved and restored:
ip route save
/ip route restore
There's a trick.
ip route save
will save only themain
table, which is good for common use cases, but not with policy routing's additional routing tables. You can state a specific table (egip rule save table 220
) if needed. But the specialtable 0
represents all tables, usingip route save table 0
will save all of them (including for each route the table it belongs to, like would be displayed withip route show table 0
) at once. Before restoring routes, it should be preferable to flush all existing routes:ip route flush table 0 all
Example showing any routing table can be saved without having to know its value beforehand:
# ip route add table 220 unreachable 10.0.0.0/8 metric 9999
# ip route show table 220
unreachable 10.0.0.0/8 metric 9999
# ip route save table 0 > /tmp/route
# ip route flush table 0 all
# ip route show table 220
#
# ip route restore table 0 < /tmp/route
# ip route show table 220
unreachable 10.0.0.0/8 metric 9999Of course all routes from other tables, including table 254 aka
main
, are also saved and restored.ip rule save
/ip rule restore
This one is also tricky because if not flushed before it will add duplicates without complaining, and flushing the rules never flushes rule prio 0, so
rule priority 0
has to be explicitly deleted:ip rule flush
ip rule delete priority 0So to save and restore:
ip rule save > /tmp/rule
[...] just deleting, or switching to some other environment etc.
ip rule flush
ip rule delete priority 0
ip rule restore < /tmp/rule
I hope you can find some usage of this, for example for automatization with multiple network namespaces.
Thanks for a very detailed answer :) I actually wanted to restore the links too, as I did create few namespaces, bridges and veth links. But I have also realized with all the complexity, it's a good idea to reconfigure manually or with scripts than trying to restore.:)
– GP92
Mar 18 at 5:01
add a comment |
Your network configuration should be saved in files such as /etc/sysconfig/network-scripts/ifconfig-(interface) and /etc/sysconfig/network, /etc/resolv.conf, etc. You should just modify these files and restart your network service rather then making your changes on the fly. Any changes you make on the fly, like route or IP changes, will be lost when your system restarts.
Hi.. yes, I know the use of the config files.but I'm checking if it's possible to generate config files or a restoration script automatically from the current state.. anyhow I think it's a dead end :|
– GP92
Mar 16 at 11:26
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f506504%2fis-there-a-way-to-save-current-state-of-network-configuration-in-linux-into-a-da%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Some support does exist for saving addresses, routes and rules, using iproute2's ip
command.
For obvious reason, this doesn't exist for links, even if one could imagine the possibility to save some virtual links, not all ("saving" a single side of a veth-pair link with its peer accross an other network namespace? not gonna happen...), or being able to save a bridge's and bridge's ports configurations including vlan etc., this doesn't appear to exist currently.
Existing commands are:
ip address save
ip address restore
ip route save
ip route restore
ip rule save
ip rule restore
The dump format is binary and the commands will refuse to save to or restore from a tty.
I suggest restoring addresses before routes (rules can be done at any order), or most saved routes won't be restored because they can't satisfy routing conditions depending on addresses. Warning: of course all flush commands below will likely disrupt network connectivity until the restore is done, so this should be avoided from remote network access (or be done in other network namespaces).
ip address save
/ip address restore
So to copy addresses from a simple network namespace
orig
's configuration having adummy0
interface (to keep the example simple) to a namespacecopy
:ip netns add orig
ip netns exec orig sh << 'EOF'
ip link add dummy0 type dummy
ip address add dev dummy0 192.0.2.2/24
ip address add dev dummy0 2001:db8:0:1::2/64
ip link set dummy0 up
ip address save > /tmp/address
EOF
ip netns add copy
ip netns exec copy sh << 'EOF'
ip link add dummy0 type dummy
ip link set dummy0 up
ip address restore < /tmp/address
ip -br address
EOFwill give for example this result:
lo DOWN
dummy0 UNKNOWN 192.0.2.2/24 2001:db8:0:1::2/64 fe80::68e3:bdff:feb0:6e85/64 fe80::e823:d1ff:fe8c:3a15/64Note: that previous automatic IPv6 link-local (
scope link
) address was also saved, and is thus restored, leading to an additional (and wrong) IPv6 link-local address, because the link/ether address (here inorig
6a:e3:bd:b0:6e:85
) on which is based the IPv6 link-local address is not saved and thus not restored (leaving here the incopy
the other random MACea:23:d1:8c:3a:15
ondummy0
). So care should actually be done to separately save and copy the MAC address of such virtual interfaces if it really matters, or prune after some addresses for physical interfaces.You should probably flush all addresses before restoring them to avoid leaving old ones if the environment wasn't a "clean slate". Contrary to routes below, I couldn't find a simple way to flush all of them in one command without having to state an interface. Using those two should be good enough:
ip address flush permanent
ip address flush temporary
On the same principle, routes and rules can be saved and restored:
ip route save
/ip route restore
There's a trick.
ip route save
will save only themain
table, which is good for common use cases, but not with policy routing's additional routing tables. You can state a specific table (egip rule save table 220
) if needed. But the specialtable 0
represents all tables, usingip route save table 0
will save all of them (including for each route the table it belongs to, like would be displayed withip route show table 0
) at once. Before restoring routes, it should be preferable to flush all existing routes:ip route flush table 0 all
Example showing any routing table can be saved without having to know its value beforehand:
# ip route add table 220 unreachable 10.0.0.0/8 metric 9999
# ip route show table 220
unreachable 10.0.0.0/8 metric 9999
# ip route save table 0 > /tmp/route
# ip route flush table 0 all
# ip route show table 220
#
# ip route restore table 0 < /tmp/route
# ip route show table 220
unreachable 10.0.0.0/8 metric 9999Of course all routes from other tables, including table 254 aka
main
, are also saved and restored.ip rule save
/ip rule restore
This one is also tricky because if not flushed before it will add duplicates without complaining, and flushing the rules never flushes rule prio 0, so
rule priority 0
has to be explicitly deleted:ip rule flush
ip rule delete priority 0So to save and restore:
ip rule save > /tmp/rule
[...] just deleting, or switching to some other environment etc.
ip rule flush
ip rule delete priority 0
ip rule restore < /tmp/rule
I hope you can find some usage of this, for example for automatization with multiple network namespaces.
Thanks for a very detailed answer :) I actually wanted to restore the links too, as I did create few namespaces, bridges and veth links. But I have also realized with all the complexity, it's a good idea to reconfigure manually or with scripts than trying to restore.:)
– GP92
Mar 18 at 5:01
add a comment |
Some support does exist for saving addresses, routes and rules, using iproute2's ip
command.
For obvious reason, this doesn't exist for links, even if one could imagine the possibility to save some virtual links, not all ("saving" a single side of a veth-pair link with its peer accross an other network namespace? not gonna happen...), or being able to save a bridge's and bridge's ports configurations including vlan etc., this doesn't appear to exist currently.
Existing commands are:
ip address save
ip address restore
ip route save
ip route restore
ip rule save
ip rule restore
The dump format is binary and the commands will refuse to save to or restore from a tty.
I suggest restoring addresses before routes (rules can be done at any order), or most saved routes won't be restored because they can't satisfy routing conditions depending on addresses. Warning: of course all flush commands below will likely disrupt network connectivity until the restore is done, so this should be avoided from remote network access (or be done in other network namespaces).
ip address save
/ip address restore
So to copy addresses from a simple network namespace
orig
's configuration having adummy0
interface (to keep the example simple) to a namespacecopy
:ip netns add orig
ip netns exec orig sh << 'EOF'
ip link add dummy0 type dummy
ip address add dev dummy0 192.0.2.2/24
ip address add dev dummy0 2001:db8:0:1::2/64
ip link set dummy0 up
ip address save > /tmp/address
EOF
ip netns add copy
ip netns exec copy sh << 'EOF'
ip link add dummy0 type dummy
ip link set dummy0 up
ip address restore < /tmp/address
ip -br address
EOFwill give for example this result:
lo DOWN
dummy0 UNKNOWN 192.0.2.2/24 2001:db8:0:1::2/64 fe80::68e3:bdff:feb0:6e85/64 fe80::e823:d1ff:fe8c:3a15/64Note: that previous automatic IPv6 link-local (
scope link
) address was also saved, and is thus restored, leading to an additional (and wrong) IPv6 link-local address, because the link/ether address (here inorig
6a:e3:bd:b0:6e:85
) on which is based the IPv6 link-local address is not saved and thus not restored (leaving here the incopy
the other random MACea:23:d1:8c:3a:15
ondummy0
). So care should actually be done to separately save and copy the MAC address of such virtual interfaces if it really matters, or prune after some addresses for physical interfaces.You should probably flush all addresses before restoring them to avoid leaving old ones if the environment wasn't a "clean slate". Contrary to routes below, I couldn't find a simple way to flush all of them in one command without having to state an interface. Using those two should be good enough:
ip address flush permanent
ip address flush temporary
On the same principle, routes and rules can be saved and restored:
ip route save
/ip route restore
There's a trick.
ip route save
will save only themain
table, which is good for common use cases, but not with policy routing's additional routing tables. You can state a specific table (egip rule save table 220
) if needed. But the specialtable 0
represents all tables, usingip route save table 0
will save all of them (including for each route the table it belongs to, like would be displayed withip route show table 0
) at once. Before restoring routes, it should be preferable to flush all existing routes:ip route flush table 0 all
Example showing any routing table can be saved without having to know its value beforehand:
# ip route add table 220 unreachable 10.0.0.0/8 metric 9999
# ip route show table 220
unreachable 10.0.0.0/8 metric 9999
# ip route save table 0 > /tmp/route
# ip route flush table 0 all
# ip route show table 220
#
# ip route restore table 0 < /tmp/route
# ip route show table 220
unreachable 10.0.0.0/8 metric 9999Of course all routes from other tables, including table 254 aka
main
, are also saved and restored.ip rule save
/ip rule restore
This one is also tricky because if not flushed before it will add duplicates without complaining, and flushing the rules never flushes rule prio 0, so
rule priority 0
has to be explicitly deleted:ip rule flush
ip rule delete priority 0So to save and restore:
ip rule save > /tmp/rule
[...] just deleting, or switching to some other environment etc.
ip rule flush
ip rule delete priority 0
ip rule restore < /tmp/rule
I hope you can find some usage of this, for example for automatization with multiple network namespaces.
Thanks for a very detailed answer :) I actually wanted to restore the links too, as I did create few namespaces, bridges and veth links. But I have also realized with all the complexity, it's a good idea to reconfigure manually or with scripts than trying to restore.:)
– GP92
Mar 18 at 5:01
add a comment |
Some support does exist for saving addresses, routes and rules, using iproute2's ip
command.
For obvious reason, this doesn't exist for links, even if one could imagine the possibility to save some virtual links, not all ("saving" a single side of a veth-pair link with its peer accross an other network namespace? not gonna happen...), or being able to save a bridge's and bridge's ports configurations including vlan etc., this doesn't appear to exist currently.
Existing commands are:
ip address save
ip address restore
ip route save
ip route restore
ip rule save
ip rule restore
The dump format is binary and the commands will refuse to save to or restore from a tty.
I suggest restoring addresses before routes (rules can be done at any order), or most saved routes won't be restored because they can't satisfy routing conditions depending on addresses. Warning: of course all flush commands below will likely disrupt network connectivity until the restore is done, so this should be avoided from remote network access (or be done in other network namespaces).
ip address save
/ip address restore
So to copy addresses from a simple network namespace
orig
's configuration having adummy0
interface (to keep the example simple) to a namespacecopy
:ip netns add orig
ip netns exec orig sh << 'EOF'
ip link add dummy0 type dummy
ip address add dev dummy0 192.0.2.2/24
ip address add dev dummy0 2001:db8:0:1::2/64
ip link set dummy0 up
ip address save > /tmp/address
EOF
ip netns add copy
ip netns exec copy sh << 'EOF'
ip link add dummy0 type dummy
ip link set dummy0 up
ip address restore < /tmp/address
ip -br address
EOFwill give for example this result:
lo DOWN
dummy0 UNKNOWN 192.0.2.2/24 2001:db8:0:1::2/64 fe80::68e3:bdff:feb0:6e85/64 fe80::e823:d1ff:fe8c:3a15/64Note: that previous automatic IPv6 link-local (
scope link
) address was also saved, and is thus restored, leading to an additional (and wrong) IPv6 link-local address, because the link/ether address (here inorig
6a:e3:bd:b0:6e:85
) on which is based the IPv6 link-local address is not saved and thus not restored (leaving here the incopy
the other random MACea:23:d1:8c:3a:15
ondummy0
). So care should actually be done to separately save and copy the MAC address of such virtual interfaces if it really matters, or prune after some addresses for physical interfaces.You should probably flush all addresses before restoring them to avoid leaving old ones if the environment wasn't a "clean slate". Contrary to routes below, I couldn't find a simple way to flush all of them in one command without having to state an interface. Using those two should be good enough:
ip address flush permanent
ip address flush temporary
On the same principle, routes and rules can be saved and restored:
ip route save
/ip route restore
There's a trick.
ip route save
will save only themain
table, which is good for common use cases, but not with policy routing's additional routing tables. You can state a specific table (egip rule save table 220
) if needed. But the specialtable 0
represents all tables, usingip route save table 0
will save all of them (including for each route the table it belongs to, like would be displayed withip route show table 0
) at once. Before restoring routes, it should be preferable to flush all existing routes:ip route flush table 0 all
Example showing any routing table can be saved without having to know its value beforehand:
# ip route add table 220 unreachable 10.0.0.0/8 metric 9999
# ip route show table 220
unreachable 10.0.0.0/8 metric 9999
# ip route save table 0 > /tmp/route
# ip route flush table 0 all
# ip route show table 220
#
# ip route restore table 0 < /tmp/route
# ip route show table 220
unreachable 10.0.0.0/8 metric 9999Of course all routes from other tables, including table 254 aka
main
, are also saved and restored.ip rule save
/ip rule restore
This one is also tricky because if not flushed before it will add duplicates without complaining, and flushing the rules never flushes rule prio 0, so
rule priority 0
has to be explicitly deleted:ip rule flush
ip rule delete priority 0So to save and restore:
ip rule save > /tmp/rule
[...] just deleting, or switching to some other environment etc.
ip rule flush
ip rule delete priority 0
ip rule restore < /tmp/rule
I hope you can find some usage of this, for example for automatization with multiple network namespaces.
Some support does exist for saving addresses, routes and rules, using iproute2's ip
command.
For obvious reason, this doesn't exist for links, even if one could imagine the possibility to save some virtual links, not all ("saving" a single side of a veth-pair link with its peer accross an other network namespace? not gonna happen...), or being able to save a bridge's and bridge's ports configurations including vlan etc., this doesn't appear to exist currently.
Existing commands are:
ip address save
ip address restore
ip route save
ip route restore
ip rule save
ip rule restore
The dump format is binary and the commands will refuse to save to or restore from a tty.
I suggest restoring addresses before routes (rules can be done at any order), or most saved routes won't be restored because they can't satisfy routing conditions depending on addresses. Warning: of course all flush commands below will likely disrupt network connectivity until the restore is done, so this should be avoided from remote network access (or be done in other network namespaces).
ip address save
/ip address restore
So to copy addresses from a simple network namespace
orig
's configuration having adummy0
interface (to keep the example simple) to a namespacecopy
:ip netns add orig
ip netns exec orig sh << 'EOF'
ip link add dummy0 type dummy
ip address add dev dummy0 192.0.2.2/24
ip address add dev dummy0 2001:db8:0:1::2/64
ip link set dummy0 up
ip address save > /tmp/address
EOF
ip netns add copy
ip netns exec copy sh << 'EOF'
ip link add dummy0 type dummy
ip link set dummy0 up
ip address restore < /tmp/address
ip -br address
EOFwill give for example this result:
lo DOWN
dummy0 UNKNOWN 192.0.2.2/24 2001:db8:0:1::2/64 fe80::68e3:bdff:feb0:6e85/64 fe80::e823:d1ff:fe8c:3a15/64Note: that previous automatic IPv6 link-local (
scope link
) address was also saved, and is thus restored, leading to an additional (and wrong) IPv6 link-local address, because the link/ether address (here inorig
6a:e3:bd:b0:6e:85
) on which is based the IPv6 link-local address is not saved and thus not restored (leaving here the incopy
the other random MACea:23:d1:8c:3a:15
ondummy0
). So care should actually be done to separately save and copy the MAC address of such virtual interfaces if it really matters, or prune after some addresses for physical interfaces.You should probably flush all addresses before restoring them to avoid leaving old ones if the environment wasn't a "clean slate". Contrary to routes below, I couldn't find a simple way to flush all of them in one command without having to state an interface. Using those two should be good enough:
ip address flush permanent
ip address flush temporary
On the same principle, routes and rules can be saved and restored:
ip route save
/ip route restore
There's a trick.
ip route save
will save only themain
table, which is good for common use cases, but not with policy routing's additional routing tables. You can state a specific table (egip rule save table 220
) if needed. But the specialtable 0
represents all tables, usingip route save table 0
will save all of them (including for each route the table it belongs to, like would be displayed withip route show table 0
) at once. Before restoring routes, it should be preferable to flush all existing routes:ip route flush table 0 all
Example showing any routing table can be saved without having to know its value beforehand:
# ip route add table 220 unreachable 10.0.0.0/8 metric 9999
# ip route show table 220
unreachable 10.0.0.0/8 metric 9999
# ip route save table 0 > /tmp/route
# ip route flush table 0 all
# ip route show table 220
#
# ip route restore table 0 < /tmp/route
# ip route show table 220
unreachable 10.0.0.0/8 metric 9999Of course all routes from other tables, including table 254 aka
main
, are also saved and restored.ip rule save
/ip rule restore
This one is also tricky because if not flushed before it will add duplicates without complaining, and flushing the rules never flushes rule prio 0, so
rule priority 0
has to be explicitly deleted:ip rule flush
ip rule delete priority 0So to save and restore:
ip rule save > /tmp/rule
[...] just deleting, or switching to some other environment etc.
ip rule flush
ip rule delete priority 0
ip rule restore < /tmp/rule
I hope you can find some usage of this, for example for automatization with multiple network namespaces.
edited Mar 16 at 14:22
answered Mar 16 at 14:16
A.BA.B
6,14711131
6,14711131
Thanks for a very detailed answer :) I actually wanted to restore the links too, as I did create few namespaces, bridges and veth links. But I have also realized with all the complexity, it's a good idea to reconfigure manually or with scripts than trying to restore.:)
– GP92
Mar 18 at 5:01
add a comment |
Thanks for a very detailed answer :) I actually wanted to restore the links too, as I did create few namespaces, bridges and veth links. But I have also realized with all the complexity, it's a good idea to reconfigure manually or with scripts than trying to restore.:)
– GP92
Mar 18 at 5:01
Thanks for a very detailed answer :) I actually wanted to restore the links too, as I did create few namespaces, bridges and veth links. But I have also realized with all the complexity, it's a good idea to reconfigure manually or with scripts than trying to restore.:)
– GP92
Mar 18 at 5:01
Thanks for a very detailed answer :) I actually wanted to restore the links too, as I did create few namespaces, bridges and veth links. But I have also realized with all the complexity, it's a good idea to reconfigure manually or with scripts than trying to restore.:)
– GP92
Mar 18 at 5:01
add a comment |
Your network configuration should be saved in files such as /etc/sysconfig/network-scripts/ifconfig-(interface) and /etc/sysconfig/network, /etc/resolv.conf, etc. You should just modify these files and restart your network service rather then making your changes on the fly. Any changes you make on the fly, like route or IP changes, will be lost when your system restarts.
Hi.. yes, I know the use of the config files.but I'm checking if it's possible to generate config files or a restoration script automatically from the current state.. anyhow I think it's a dead end :|
– GP92
Mar 16 at 11:26
add a comment |
Your network configuration should be saved in files such as /etc/sysconfig/network-scripts/ifconfig-(interface) and /etc/sysconfig/network, /etc/resolv.conf, etc. You should just modify these files and restart your network service rather then making your changes on the fly. Any changes you make on the fly, like route or IP changes, will be lost when your system restarts.
Hi.. yes, I know the use of the config files.but I'm checking if it's possible to generate config files or a restoration script automatically from the current state.. anyhow I think it's a dead end :|
– GP92
Mar 16 at 11:26
add a comment |
Your network configuration should be saved in files such as /etc/sysconfig/network-scripts/ifconfig-(interface) and /etc/sysconfig/network, /etc/resolv.conf, etc. You should just modify these files and restart your network service rather then making your changes on the fly. Any changes you make on the fly, like route or IP changes, will be lost when your system restarts.
Your network configuration should be saved in files such as /etc/sysconfig/network-scripts/ifconfig-(interface) and /etc/sysconfig/network, /etc/resolv.conf, etc. You should just modify these files and restart your network service rather then making your changes on the fly. Any changes you make on the fly, like route or IP changes, will be lost when your system restarts.
answered Mar 16 at 0:48
L.RayL.Ray
35119
35119
Hi.. yes, I know the use of the config files.but I'm checking if it's possible to generate config files or a restoration script automatically from the current state.. anyhow I think it's a dead end :|
– GP92
Mar 16 at 11:26
add a comment |
Hi.. yes, I know the use of the config files.but I'm checking if it's possible to generate config files or a restoration script automatically from the current state.. anyhow I think it's a dead end :|
– GP92
Mar 16 at 11:26
Hi.. yes, I know the use of the config files.but I'm checking if it's possible to generate config files or a restoration script automatically from the current state.. anyhow I think it's a dead end :|
– GP92
Mar 16 at 11:26
Hi.. yes, I know the use of the config files.but I'm checking if it's possible to generate config files or a restoration script automatically from the current state.. anyhow I think it's a dead end :|
– GP92
Mar 16 at 11:26
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f506504%2fis-there-a-way-to-save-current-state-of-network-configuration-in-linux-into-a-da%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Doesn't iptables-save work at all?
– Raman Sailopal
Mar 15 at 13:07
iptables-save working for saving iptable rules. I am looking for a similar way to save network configuration. However, I can think of some reasons why it may not be possible to save network configuration entirely, as if a physical interface is missing at the time of restore, few configurations may fail.
– GP92
Mar 15 at 13:22