
私は Xen を初めて使用しており、同じゲスト VPS に 2 つの異なる IP を追加する方法を理解しようとしています。
まず、32GB の RAM と 2 つの NIC を搭載した物理サーバーであるノードの設定について説明します。最初の NIC のパブリック IP は 82.XXX.YYY.ZZZ で、2 番目の NIC は cPanel サーバーに接続する内部ネットワーク用で、プライベート IP は 192.168.XXX.YYY です。
これまでテストしたところ、パブリック ネットワークまたはプライベート ネットワークのいずれかを使用する VPS のみを作成できましたが、両方を使用する VPS は作成できませんでした。パブリック IP またはプライベート IP のいずれかを使用して VPS を作成すると、それらに ping を実行でき、SSH 経由で接続することもできます。
しかし、たとえば、ノードと同じサブネット (82.XXX.YYY.ZZZ) の IP を使用する VPS を作成し、プライベート IP を追加しようとすると、内部ネットワークからプライベート IP に ping できません。また、その逆の場合も同様で、プライベート IP (192.168.XXX.YYY) で VPS を作成した場合、内部ネットワークから接続して ping できますが、パブリック IP を追加した場合は、ping も接続もできません。
また、この情報がこの問題に役立つかどうかはわかりませんが、私は VPS 管理 (VPS の作成、IP 割り当て、VPS の削除など) に SolusVM を使用しています。
この問題を解決するために他にどのような情報を提供する必要があるか教えてください。
答え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
domu イメージを作成するために xen-tool を設定するには、/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