一个在远程主机自动修改网卡的脚本, 带回滚

2020-09-08 10:43:49 +08:00
 firejoke

当初为了修改远程主机网卡配置写的一个脚本, 可以配合 fabric 在页面上修改远程主机的网卡配置
最开始只做了 redhat 系的网卡配置文件的解析和修改, 现在做了 debian 系的适配
支持网卡配置修改和 bond 网卡创建(bond 在 redhat 系下测试效果不错, debian 系还没测几次)
如果是远程调用的话, 可以用 nohup, 避免阻塞, 然后在重新连上后, 查看 /tmp/下 network-interfaces-stdout 和 network-interfaces-stderr 这两个临时文件内的输出结果
git 地址

python /tmp/network/network_interface.py --help             
usage: network_interface.py [-h] [--netifaces] [--alter name, config json]
                            [--tty 1 or 0]

You must run as root!

optional arguments:
  -h, --help            show this help message and exit
  --netifaces           get network interfaces
  --alter name, config json
                        Alter network interfaces config, new config must be
                        json string
  --tty 1 or 0          1: Output to terminal, 0: tmp file(/tmp/network-
                        interfaces-std*), default: 0

e.g.:
get network interfaces config
    python network_interface.py --netifaces
alter network interface config
    python network_interface.py --alter ens33 '{"ip_address": ["192.168.50.1", ....],
    "gateway": "192.168.50.254", "dns": ["1.2.4.8", ...]}'
    or
    python network_interface.py --alter ens37 '{"reset_dhcp": 1}'
    or
    python network_interface.py --alter ens37 '{"reset_promisc": 1}'
    python network_interface.py --alter ens37 '{"reset_none": 1}'
remote
    $(nohup python /tmp/network/network_interface.pyc --alter 'json str' >& /dev/null < /dev/null &) && sleep 1

            """
1311 次点击
所在节点    Python
0 条回复

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/705104

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX