
我是 Xen 新手,我試圖了解如何在同一個來賓 VPS 上添加 2 個不同的 IP。
首先,我將解釋我的節點設置,這是一個具有 32GB RAM 和 2 個網路卡的實體伺服器。第一個 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 guest 建立 Xen 磁碟映像(環回映像) 使用主機名稱 testa、磁碟 10G、交換 1G、ram/記憶體 512M、dhcp、vcpu 3、作業系統 Debian jessie 建立 xen guest:
# 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