首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Centos网络接口的备份和恢复

Centos网络接口的备份和恢复
EN

Unix & Linux用户
提问于 2018-03-28 13:44:24
回答 2查看 2.4K关注 0票数 5

我有一个服务器运行Centos 7,需要重新启动来升级一些软件。

一些物理NIC有大约5-10个VLAN接口。它们可能会在每周/每个月的基础上进行更改,因此将细节存储在/etc/sysconfig/network-scripts中以便在重新启动期间持久存在是不实际的。

是否有一种简单的方法可以在重新启动后获取当前网络堆栈的快照并进行还原?类似于保存/还原iptables规则的方式?

我已经找到了几个对system-config-network-cmd的引用,但是如果它覆盖了我们在/etc/sysconfig/network-scripts中拥有的物理接口的静态信任,我对使用这个工具非常谨慎。

谢谢!

EN

回答 2

Unix & Linux用户

发布于 2018-03-28 14:53:40

Iptable是你要求的最简单的部分。

iptables-save可以用来保存当前的iptables规则,然后可以用iptables-restore读取这些规则。

代码语言:javascript
复制
# 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

对于您任务中的网络部分,如果您没有使用“网络管理器”服务(许多人在服务器上不使用该服务),那么system-config-network-cmd或更高版本的替换(如nmtui\\nmcli)就不会有多大作用。

在某种程度上,您必须编写自己的解决方案脚本,类似于捕获ip addr show的输出,并将其解析为创建ip批处理文件(有关有用信息,请参阅:https://support.cumulusnetworks.com/hc/en-us/articles/202395708-Bringing-up-Large-Networks-Using-ip-batch ),然后通过ip --batch <batchfile>重放该批处理文件,并根据详细程度进行调整。你需要MACs能保持原样吗?其他的设备选择?有什么特定的vlans吗?还是仅仅是在同一个子网上的所有IP地址?哦,如果您在重新启动后需要配置任何短暂的路由,那么您也可能希望捕获ip route show

长期而言,可能会考虑使用Ansible (或类似的)来管理短暂的iptables规则和短暂的网络接口配置的部署。然后你就可以重放你的剧本,把所有的东西都拿回来。

票数 0
EN

Unix & Linux用户

发布于 2018-03-28 14:59:01

首先,必须确保已经安装了NetworkManager并存在nmcli命令。

之后,通过nmcli显示当前的网络连接:

代码语言:javascript
复制
# 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

接口enp0s8.10不是通过NetworkManager添加的。我已经在vconfigip l upip a上添加了它。

接口必须是向上的和IP地址分配!如果接口没有启动,或者没有分配IP,那么NetworkManager将显示它为非托管的。

之后,您可以调用nmcli来编辑活动连接:

代码语言:javascript
复制
# 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

在完成这些步骤之后,您将在/etc/sysconfig/network-scripts文件ifcfg-enp0s8.10中看到用于接口的配置文件(如我的例子)。

当然,你应该通过你所有的接口。

票数 0
EN
页面原文内容由Unix & Linux提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://unix.stackexchange.com/questions/434094

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档