libvirt 網路配置 bridge

2021-09-01 10:28:42 字數 3248 閱讀 4702

bridge方式配置libvirt網路

1、network.xml

local

其中192.168.0.204是host的ip,閘道器為192.168.0.254 

root@204:/opt# virsh net-define network.xml

root@204:/opt# virsh net-autostart local

root@204:/opt# virsh net-start local

如果報錯:

error: failed to create network from network.xml

error: internal error network is already in use by inte***ce eth0

先 ifconfig eth0 down

2、修改 /etc/network/inte***ce,只保留 lo

auto lo

iface lo inet loopback

dns-nameservers 192.168.0.254

3、開機自動啟動指令碼:

#!/bin/sh

sleep 3

ifconfig eth0 up

brctl add local eth0

route del default

route add default gw 192.168.0.254 metric 0 dev local

指令碼加入/etc/rc.local中

4、重啟機器  reboot,即可看到:

root@204:~# virsh net-list --all

name state autostart

-----------------------------------------

default active yes

local active yes

eth0      link encap:ethernet  hwaddr 00:1e:68:04:74:68

inet6 addr: fe80::21e:68ff:fe04:7468/64 scope:link

up broadcast running multicast mtu:1500 metric:1

rx packets:3085 errors:0 dropped:0 overruns:0 frame:0

tx packets:248 errors:0 dropped:0 overruns:0 carrier:0

collisions:0 txqueuelen:1000

rx bytes:491876 (491.8 kb) tx bytes:43962 (43.9 kb)

interrupt:18 memory:fd9e0000-fda00000

lo link encap:local loopback

inet addr:127.0.0.1 mask:255.0.0.0

inet6 addr: ::1/128 scope:host

up loopback running mtu:16436 metric:1

rx packets:167 errors:0 dropped:0 overruns:0 frame:0

tx packets:167 errors:0 dropped:0 overruns:0 carrier:0

collisions:0 txqueuelen:0

rx bytes:8376 (8.3 kb) tx bytes:8376 (8.3 kb)

local link encap:ethernet hwaddr 00:1e:68:04:74:68

inet addr:192.168.0.204 bcast:192.168.0.255 mask:255.255.255.0

up broadcast running multicast mtu:1500 metric:1

rx packets:1308 errors:0 dropped:0 overruns:0 frame:0

tx packets:238 errors:0 dropped:0 overruns:0 carrier:0

collisions:0 txqueuelen:0

rx bytes:132498 (132.4 kb) tx bytes:41842 (41.8 kb)

virbr0 link encap:ethernet hwaddr ea:44:0a:49:d4:50

inet addr:192.168.122.1 bcast:192.168.122.255 mask:255.255.255.0

up broadcast multicast mtu:1500 metric:1

rx packets:0 errors:0 dropped:0 overruns:0 frame:0

tx packets:0 errors:0 dropped:0 overruns:0 carrier:0

collisions:0 txqueuelen:0

rx bytes:0 (0.0 b) tx bytes:0 (0.0 b)

root@204:/opt# route

kernel ip routing table

destination gateway genmask flags metric ref use iface

default 192.168.0.254 0.0.0.0 ug 0 0 0 local

192.168.0.0 * 255.255.255.0 u 0 0 0 local

192.168.122.0 * 255.255.255.0 u 0 0 0 virbr0

root@204:/opt#

虛擬機器就可以使用和主機在同乙個網段的ip了,在domain的配置檔案中inte***ce的配置段:

libvirt開啟NAT預設網路模式

之前的kvm虛擬機器都是使用網橋的模式,突然要求使用nat模式,記錄一下方法 1.關閉主機上的所有虛擬機器 2.在命令列下執行命令刪除舊的虛擬網橋 root brctl delbr virbr0 3.在命令列下執行命令刪除舊的虛擬網橋配置檔案 root rm rf etc sysconfig net...

網路 linux網路配置

zlm ubuntu sudo ifconfig eth0 192.168.1.109 netmask 255.255.255.0 broadcast 192.168.1.255 zlm ubuntu sudo route add del default gw 192.168.1.1 新增刪除閘道器...

linux配置 網路配置

ip位址,子網掩碼,閘道器 設定ip位址,子網掩碼並啟用 ifconfig eth0 10.192.77.250 netmask 255.255.255.0 up 注 ip,掩碼,閘道器都設定到 etc sysconfig network scripts ifcfg eth0裡面了。設定多ip 可以...