Xen VPS 具有来自两个不同子网的 2 个 IP

Xen VPS 具有来自两个不同子网的 2 个 IP

我是 Xen 的新手,我正在尝试了解如何在同一个来宾 VPS 上添加 2 个不同的 IP。

首先,我将介绍我的节点设置,它是一台物理服务器,配备 32GB RAM 和 2 个 NIC。第一个 NIC 具有公共 IP 82.XXX.YYY.ZZZ,第二个 NIC 用于连接到 cPanel 服务器的内部网络 - 私有 IP 192.168.XXX.YYY。

从我到目前为止的测试来看,我只能创建一个使用公网或私网的 VPS,但不能同时使用两者。如果我使用公网 IP 或私网 IP 创建 VPS,我可以 ping 它们,也可以通过 SSH 连接。

但是例如,如果我创建一个使用与节点位于同一子网的某个 IP(82.XXX.YYY.ZZZ)的 VPS,然后尝试添加一个私有 IP,则无法从内部网络 ping 通该私有 IP,反之亦然,如果我创建一个具有私有 IP(192.168.XXX.YYY)的 VPS,我可以从内部网络连接到它并 ping 通它,但如果我添加一个公共 IP,则无法 ping 通它或连接到它。

另外,我不知道这些信息是否有助于解决这个问题,但我使用 SolusVM 进行 VPS 管理(创建 VPS、IP 分配、删除 VPS 等)。

请告诉我还需要提供哪些其他信息来解决这个问题。

答案1

配置桥接网络:

Edit /etc/network/interfaces
# vi /etc/network/interfaces
...
auto eth0
iface eth0 inet manual

auto br0
iface br0 inet static
        address [ipv4]
        netmask [netmask]
        network [network]
        broadcast [broadcast]
        gateway [ipv4gateway]
        bridge_ports eth0
        bridge_stp on
        bridge_maxwait 0
iface br0 inet6 static
        address [ipv6]
        netmask 64
        dns-nameservers [dnsipv6]
        gateway [ipv6gatewaay]
        autoconf 0
# internal
auto virbr0
iface virbr0 inet static
        address 192.168.0.1
        netmask 255.255.255.0
        broadcast 192.168.0.255
        pre-up brctl addbr virbr0

编辑 /etc/sysctl.conf.d

net.ipv4.ip_forward = 1
net.ipv6.conf.all.forwarding=1
net.bridge.bridge-nf-call-ip6tables = 0
net.bridge.bridge-nf-call-iptables = 0
net.bridge.bridge-nf-call-arptables = 0 

手动添加 virbr0

# brctl addbr virbr0
# ifconfig virbr0 192.168.0.1 netmask 255.255.255.0 up  

为 domu 安装和配置 dhcp 服务器 安装 isc-dhcp-server

# apt-get install isc-dhcp-server 

编辑 /etc/default/isc-dhcp-server

INTERFACES="virbr0"
Edit /etc/dhcp/dhcpd.conf
subnet 192.168.0.0 netmask 255.255.255.0 {
  range 192.168.0.10 192.168.0.50;
  option routers 192.168.0.1;
  default-lease-time 600;
  max-lease-time 7200;
}

重启 dhcp 服务器

# service isc-dhcp-server restart

配置 xen-tool 来创建 domu 镜像 编辑 /etc/xen-tools/xen-tools.conf

#Begin by setting the dir = directive to the directory into which the tools are to create the Xen guest image files:
dir = /home/images
#lvm = myvolgroup -> if using LVM (logical volume management)
install-method = debootstrap
debootstrap-cmd = /usr/sbin/debootstrap
size   = 4G       # Root disk, suffix (G, M, k) required
memory = 512M # Suffix (G, M, k) required
swap   = 1G # Suffix (G, M, k) required
fs     = ext3     # Default file system for any disk
dist   = `jessie` # Default distribution is determined by Dom0's distribution
image  = sparse   # Specify sparse vs. full disk images (file based images only)
# for static
# gateway    = 192.168.1.1
# netmask    = 255.255.255.0
# broadcast  = 192.168.1.255
dhcp=1
bridge = virbr0
genpass_len = 8
passwd = 1
kernel      = /boot/vmlinuz-`uname -r`
initrd      = /boot/initrd.img-`uname -r`
pygrub = 1
mirror = http://debian.mirrors.ovh.net/debian
mirror_jessie = http://http.debian.net/debian
ext4_options     = noatime,nodiratime,errors=remount-ro 
ext3_options     = noatime,nodiratime,errors=remount-ro
ext2_options     = noatime,nodiratime,errors=remount-ro
xfs_options      = defaults
reiserfs_options = defaults
btrfs_options    = defaults
output    = /etc/xen

extension = .cfg

为 Xen 客户机创建 Xen 磁盘映像(环回映像) 创建主机名为 testa、磁盘 10G、交换 1G、RAM/内存 512M、dhcp、vcpu 3、OS Debiean jessie 的 xen 客户机:

# xen-create-image --hostname testa --size=10Gb --swap=1024Mb --memory=512Mb --vcpu=3  --dist=jessie
Can't exec "jessie": No such file or directory at /usr/share/perl5/Xen/Tools/Common.pm line 100, <FILE> line 134.
Use of uninitialized value $output in scalar chomp at /usr/share/perl5/Xen/Tools/Common.pm line 101, <FILE> line 134.
Use of uninitialized value $output in concatenation (.) or string at /usr/share/perl5/Xen/Tools/Common.pm line 104, <FILE> line 134.

General Information
--------------------
Hostname       :  testa
Distribution   :  jessie
Mirror         :  http://debian.mirrors.ovh.net/debian
Partitions     :  swap            1024Mb (swap)
                  /               10Gb  (ext3)
Image type     :  sparse
Memory size    :  512Mb
Bootloader     :  pygrub

Networking Information
----------------------
IP Address     : DHCP [MAC: 00:16:3E:73:6F:31]


Creating partition image: /home/vmimages/domains/testa/swap.img
Done

Creating swap on /home/vmimages/domains/testa/swap.img
Done

Creating partition image: /home/vmimages/domains/testa/disk.img
Done

Creating ext3 filesystem on /home/vmimages/domains/testa/disk.img
Done
Installation method: debootstrap
Done

Running hooks
Done

No role scripts were specified.  Skipping

Creating Xen configuration file
Done

No role scripts were specified.  Skipping
Setting up root password
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
All done


Logfile produced at:
         /var/log/xen-tools/testa.log

Installation Summary
---------------------
Hostname        :  testa
Distribution    :  jessie
MAC Address     :  00:16:3E:73:6F:31
IP Address(es)  :  dynamic
RSA Fingerprint :  21:12:bb:c3:ad:34:67:6f:cd:a1:7d:d3:ef:ae:95:f5
Root Password   :  N/A

此过程大约需要 14 分钟。运行 xen guest 运行 xen guest

# xl create /etc/xen/testa.cfg -c

内部路由至互联网

# iptables -t nat -A POSTROUTING -o br0 -j MASQUERADE
# iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
# iptables -A FORWARD -i virbr0 -o br0 -m state --state RELATED,ESTABLISHED -j ACCEPT
# iptables -A FORWARD -i virbr0 -o br0 -j ACCEPT  
Internet to internal in port xxx into 192.168.0.100 port yyy
# iptables -A PREROUTING -t nat -i br0 -p tcp --dport xxx -j DNAT --to 192.168.0.100:yyy
# iptables -A FORWARD -p tcp -d 192.168.0.100 --dport yyy -j ACCEPT

使 domu 在启动后自动启动 在文件夹 /etc/xen/auto 中创建符号链接

# mkdir /etc/xen/auto
# cd /etc/xen/auto/
# ln -s /etc/xen/testa.cfg

编辑 /etc/xen/testa.cfg

# vi /etc/xen/testa.cfg
on_xend_stop='shutdown' 
on_xend_start='start'

完整说明请阅读:http://www.garasiku.web.id/web/joomla/index.php/debian/80-how-to-install-xen-in-debian-jessie

相关内容