![KVM - nat 或桥接器。我是怎么做到的](https://linux22.com/image/78047/KVM%20-%20nat%20%E6%88%96%E6%A1%A5%E6%8E%A5%E5%99%A8%E3%80%82%E6%88%91%E6%98%AF%E6%80%8E%E4%B9%88%E5%81%9A%E5%88%B0%E7%9A%84.png)
我有 Debian Jessie 服务器,并且安装了 apache 服务器。 apache 托管了多个来自不同 IP 地址的站点。我的服务器有 KVM 资源。我的问题是 -如何将我的免费 IP 设置为访客 KVM 机器。。我的免费 IP 是 eth0:3 -> 80.80.130.135 我的配置 /etc/network/interfaces 文件是:
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
auto eth0
auto eth0:0
auto eth0:1
auto eth0:2
auto eth0:3
allow-hotplug eth0
iface eth0 inet static
address 80.80.130.131
netmask 255.255.255.192
network 80.80.130.128
broadcast 80.80.130.191
gateway 80.80.130.1
# dns-* options are implemented by the resolvconf package, if installed
dns-nameservers 85.17.151.123 62.211.64.122
dns-search localdomain
iface eth0:0 inet static
address 80.80.130.132
netmask 255.255.255.192
network 80.80.130.128
gateway 80.80.130.1
# dns-* options are implemented by the resolvconf package, if installed
dns-nameservers 85.17.151.123 62.211.64.122
dns-search localdomain
iface eth0:1 inet static
address 80.80.130.133
netmask 255.255.255.192
network 80.80.130.128
broadcast 80.80.130.191
# dns-* options are implemented by the resolvconf package, if installed
dns-nameservers 85.17.151.123 62.211.64.122
dns-search localdomain
iface eth0:2 inet static
address 80.80.130.134
netmask 255.255.255.192
network 80.80.130.128
broadcast 80.80.130.191
# dns-* options are implemented by the resolvconf package, if installed
dns-nameservers 85.17.151.123 62.211.64.122
dns-search localdomain
iface eth0:3 inet static
address 80.80.130.135
netmask 255.255.255.192
network 80.80.130.128
broadcast 80.80.130.191
# dns-* options are implemented by the resolvconf package, if installed
dns-nameservers 85.17.151.123 62.211.64.122
dns-search localdomain
答案1
- 修改
/etc/network/interfaces
您的 jessie 主机,使其使用桥接接口eth0
。
例如,删除您的eth0
和eth0:*
别名定义并添加以下内容:
auto br0
iface br0 inet static
address 80.80.130.131
netmask 255.255.255.192
network 80.80.130.128
broadcast 80.80.130.191
gateway 80.80.130.1
# dns-* options are implemented by the resolvconf package, if installed
dns-nameservers 85.17.151.123 62.211.64.122
post-up ip addr add 80.80.130.132 dev br0
post-up ip addr add 80.80.130.133 dev br0
post-up ip addr add 80.80.130.134 dev br0
bridge_ports eth0
bridge_stp off
bridge_maxwait 1
bridge_fd 1
bridge_hello 2
bridge_maxage 12
重新启动后,或者ifdown -a ; ifup -a
您可以配置您的来宾:
- 配置来宾以使用
br0
.您可以使用 virt-manager 通过 GUI 来完成此操作,也可以直接使用 编辑 XML 文件virsh edit domainname
,并将接口定义更改为如下所示:
<interface type='bridge'>
<mac address='xx:xx:xx:xx:xx:xx'/>
<source bridge='br0'/>
<model type='virtio'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
</interface>
- 现在,您可以将来宾配置为使用静态 IP 80.80.130.135
/etc/network/interfaces
(如果不是其他 Debian 系统,则可以配置为适合您的 VM 的任何 IP 地址),或者您可以配置dnsmasq
将该 IP 分配给 VM 的 MAC 地址。