给VirtualBox VM新增一块桥接网卡,使用nmcli设置静态IP
Posted 王万林 Ben
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了给VirtualBox VM新增一块桥接网卡,使用nmcli设置静态IP相关的知识,希望对你有一定的参考价值。
需求
在给VirtualBox VM新增了一块桥接网卡,如何设置静态IP?
[root@localhost ~]# nmcli device status
DEVICE TYPE STATE CONNECTION
enp0s3 ethernet connected enp0s3
enp0s8 ethernet connected Wired connection 1
enp0s9 ethernet disconnected --
lo loopback unmanaged --
[root@localhost ~]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether 08:00:27:98:34:05 brd ff:ff:ff:ff:ff:ff
inet 10.0.2.15/24 brd 10.0.2.255 scope global dynamic noprefixroute enp0s3
valid_lft 85239sec preferred_lft 85239sec
inet6 fe80::a00:27ff:fe98:3405/64 scope link noprefixroute
valid_lft forever preferred_lft forever
3: enp0s8: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether 08:00:27:6f:ea:e7 brd ff:ff:ff:ff:ff:ff
inet 192.168.31.214/24 brd 192.168.31.255 scope global dynamic noprefixroute enp0s8
valid_lft 42039sec preferred_lft 42039sec
inet6 fe80::b617:f2d5:6043:769e/64 scope link noprefixroute
valid_lft forever preferred_lft forever
4: enp0s9: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether 08:00:27:38:87:60 brd ff:ff:ff:ff:ff:ff
enp0s9是一块刚添加的网卡,是disconnected的状态。
使用nmcli命令,添加一个名为test-lab的连接。如下所示,
[root@localhost ~]# nmcli con add \\
type ethernet \\
con-name test-lab \\
ifname enp0s9 \\
ip4 192.168.31.161/24 \\
gw4 192.168.31.1 \\
ipv4.dns "192.168.31.1"
Connection 'test-lab' (c86aef88-fcfa-4b76-8459-2a17fc4f8c3a) successfully added.
查看连接状态,是connected的状态了,
[root@localhost ~]# nmcli device status
DEVICE TYPE STATE CONNECTION
enp0s3 ethernet connected enp0s3
enp0s8 ethernet connected Wired connection 1
enp0s9 ethernet connected test-lab
lo loopback unmanaged
再查看IP地址设置,enp0s9已经成功设置好了,
[root@localhost ~]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether 08:00:27:98:34:05 brd ff:ff:ff:ff:ff:ff
inet 10.0.2.15/24 brd 10.0.2.255 scope global dynamic noprefixroute enp0s3
valid_lft 85572sec preferred_lft 85572sec
inet6 fe80::a00:27ff:fe98:3405/64 scope link noprefixroute
valid_lft forever preferred_lft forever
3: enp0s8: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether 08:00:27:6f:ea:e7 brd ff:ff:ff:ff:ff:ff
inet 192.168.31.214/24 brd 192.168.31.255 scope global dynamic noprefixroute enp0s8
valid_lft 42372sec preferred_lft 42372sec
inet6 fe80::b617:f2d5:6043:769e/64 scope link noprefixroute
valid_lft forever preferred_lft forever
4: enp0s9: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether 08:00:27:38:87:60 brd ff:ff:ff:ff:ff:ff
inet 192.168.31.161/24 brd 192.168.31.255 scope global noprefixroute enp0s9
valid_lft forever preferred_lft forever
inet6 fe80::9d62:3e3e:43c:aad3/64 scope link noprefixroute
valid_lft forever preferred_lft forever
总结
这就是使用nmcli为一个网卡设备添加连接信息的步骤。
参考资料
https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/networking_guide/sec-configuring_ip_networking_with_nmcli#doc-wrapperhttps://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/networking_guide/sec-configuring_ip_networking_with_nmcli#doc-wrapper
开发者涨薪指南 48位大咖的思考法则、工作方式、逻辑体系以上是关于给VirtualBox VM新增一块桥接网卡,使用nmcli设置静态IP的主要内容,如果未能解决你的问题,请参考以下文章
记录问题-VirtualBox6.1 下 配置 Ubuntu 16.04 多网卡