Note-51077-9

Token ID: 1

ERC-721 1 Transfers

Metadata

{
  "title": "虚拟机增加多个ip操作汇总",
  "tags": [
    "post",
    "linux"
  ],
  "sources": [
    "xlog"
  ],
  "external_urls": [
    "https://daxin-6967.xlog.app/xu-ni-ji-zeng-jia-duo-ge-ip-cao-zuo-hui-zong"
  ],
  "date_published": "2023-04-10T12:13:26.656Z",
  "content": "## **1. 在宿主机查看网卡**\n**- virsh attach-interface 添加网卡:**\n\n```\n[root@ubuntu ~]# virsh domiflist CentOS-V6.5.23-server01 \nInterface  Type       Source     Model       MAC\n-------------------------------------------------------\nvnet0      network    default    rtl8139     52:54:00:90:0a:7a\n\n[root@ubuntu ~]# virsh attach-interface CentOS-V6.5.23-server01 --type network --source default --model rtl8139  --live --config\nInterface attached successfully\n\n[root@ubuntu ~]# virsh domiflist  CentOS-V6.5.23-server01                                                       \nInterface  Type       Source     Model       MAC\n-------------------------------------------------------\nvnet0      network    default    rtl8139     52:54:00:90:0a:7a\nvnet1      network    default    rtl8139     52:54:00:ae:84:d0\n```\n**- virsh detach-interface 删除网卡:**\n```\n[root@ubuntu ~]# virsh detach-interface CentOS-V6.5.23-server01 --type  network --mac  52:54:00:00:34:55  --live --config\nInterface detached successfully\n\n[root@ubuntu ~]# virsh domiflist CentOS-V6.5.23-server01                                                  \nInterface  Type       Source     Model       MAC\n-------------------------------------------------------\nvnet0      network    default    rtl8139     52:54:00:90:0a:7a\n```\n\n## **2. 在虚拟机里查看新增加网卡**\n```\n[root@rhel7 ~]# nmcli device show | grep -i device   --查看网卡设备,我们可以看到新添加的enp0s8\nGENERAL.DEVICE:                         virbr0\nGENERAL.DEVICE:                         enp0s3\nGENERAL.DEVICE:                         virbr0-nic\nGENERAL.DEVICE:                         enp0s8\nGENERAL.DEVICE:                         lo\n[root@rhel7 ~]# nmcli connection show     ---还得添加网卡配置文件才能查看到enp0s8\nNAME        UUID                                  TYPE            DEVICE     \nvirbr0-nic  c6a02e0f-24af-4b3b-983d-1643fee355df  generic         virbr0-nic \nvirbr0      eecfd3a6-4d29-4f9c-a62c-1a30df56e011  bridge          virbr0     \nenp0s3      df34c879-c2bd-4c82-ae7a-39e39a2228dd  802-3-ethernet  enp0s3    \n```\n**- 添加enp0s8的网卡配置文件:**\n```\n[root@rhel7 ~]# nmcli connection add type ethernet con-name enp0s8 ifname enp0s8 autoconnect yes\nConnection 'enp0s8' (8bf108aa-9c89-4c2c-a5d3-3d9346b2c644) successfully added.\n[root@rhel7 ~]# nmcli connection show\nNAME        UUID                                  TYPE            DEVICE     \nvirbr0-nic  c6a02e0f-24af-4b3b-983d-1643fee355df  generic         virbr0-nic \nvirbr0      eecfd3a6-4d29-4f9c-a62c-1a30df56e011  bridge          virbr0     \nenp0s3      df34c879-c2bd-4c82-ae7a-39e39a2228dd  802-3-ethernet  enp0s3     \nenp0s8      8bf108aa-9c89-4c2c-a5d3-3d9346b2c644  802-3-ethernet  enp0s8    \n```\n**- 给网卡配置IP:**\n```\n[root@rhel7 ~]# cd /etc/sysconfig/network-scripts/\n[root@rhel7 ~]# vi ifcfg-enp0s8\n[root@rhel7 ~]# service network restart      ---重启网卡\nRestarting network (via systemctl):                        [  OK  ]\n\n```\n**给enp0s8再配置一个IP地址192.168.1.201:**\n```\n[root@rhel7 ~]# nmcli connection modify enp0s8 +ipv4.addresses 192.168.1.201/24 ipv4.gateway 192.168.1.99\n[root@rhel7 ~]# nmcli connection down enp0s8   --重启网卡\nConnection 'enp0s8' successfully deactivated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/13)\n[root@rhel7 ~]# nmcli connection up enp0s8\nConnection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/14)\n[root@rhel7 ~]# nmcli connection show \nNAME        UUID                                  TYPE            DEVICE     \nvirbr0-nic  c6a02e0f-24af-4b3b-983d-1643fee355df  generic         virbr0-nic \nvirbr0      eecfd3a6-4d29-4f9c-a62c-1a30df56e011  bridge          virbr0     \nenp0s3      df34c879-c2bd-4c82-ae7a-39e39a2228dd  802-3-ethernet  enp0s3     \nenp0s8      8bf108aa-9c89-4c2c-a5d3-3d9346b2c644  802-3-ethernet  enp0s8     \n[root@rhel7 ~]# ip addr show enp0s8 --查看添加成功\n3: enp0s8: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000\n    link/ether 08:00:27:79:3c:2c brd ff:ff:ff:ff:ff:ff\n    inet 192.168.1.200/24 brd 192.168.1.255 scope global enp0s8\n       valid_lft forever preferred_lft forever\n    inet 192.168.1.201/24 brd 192.168.1.255 scope global secondary enp0s8\n       valid_lft forever preferred_lft forever\n    inet6 fe80::a00:27ff:fe79:3c2c/64 scope link \n       valid_lft forever preferred_lft forever\n[root@rhel7 ~]# nmcli con delete enp0s8    --删除网卡\n```",
  "attributes": [
    {
      "value": "xu-ni-ji-zeng-jia-duo-ge-ip-cao-zuo-hui-zong",
      "trait_type": "xlog_slug"
    }
  ]
}