![CentOS 7을 사용하여 KVM 게스트에 대한 여러 경로를 정의하는 방법](https://linux55.com/image/108451/CentOS%207%EC%9D%84%20%EC%82%AC%EC%9A%A9%ED%95%98%EC%97%AC%20KVM%20%EA%B2%8C%EC%8A%A4%ED%8A%B8%EC%97%90%20%EB%8C%80%ED%95%9C%20%EC%97%AC%EB%9F%AC%20%EA%B2%BD%EB%A1%9C%EB%A5%BC%20%EC%A0%95%EC%9D%98%ED%95%98%EB%8A%94%20%EB%B0%A9%EB%B2%95.png)
다음 코드는 CentOS 7 HOST에 두 개의 CentOS 7 GUEST 가상 머신을 생성합니다. 가상 머신 중 하나는 공용 IP 주소를 통해 인터넷에 연결됩니다. 다른 가상 머신은 개인 IP 주소를 얻지만 ping
게이트웨이에 액세스하거나 ping
다른 가상 머신에서 액세스할 수 없습니다.
서버에는 두 개의 경로가 필요합니다. 각 가상 머신이 개인 IP 주소를 사용하여 서로 통신하는 경로입니다. 첫 번째 가상 머신은 공용 IP 주소를 외부 세계와 통신하기 위한 또 다른 경로로 사용합니다. 이 목표를 달성하려면 다음 중 어떤 구체적인 변화가 필요합니까?
공용 가상 머신 생성
다음 명령은 설치 중에 IP 주소와 게이트웨이, DNS, 넷마스크 등을 자동으로 성공적으로 설정하므로 결과 가상 머신이 인터넷에서 필요한 PUBLIC IP로 즉시 상호 작용할 수 있습니다.
virt-install --name=public-centos7 --disk path=/var/lib/libvirt/images/guest.img,size=50 \
--graphics none --vcpus=1 --memory=2048 --location /tmp/CentOS-7-x86_64-Minimal-1611.iso \
--network=default --os-type=linux --os-variant=rhel7.0 --initrd-inject=/tmp/vm.ks \
--extra-args "ks=file:/vm.ks console=ttyS0 ip=PUBLIC.IP.OF.VM::PUBLIC.IP.OF.GATEWAY:255.255.255.248:localhost2:eth0:none"
개인 가상 머신 만들기
다음 명령은 주소 ping PUBLIC.IP.OF.GATEWAY
가 없거나 다른 주소가 있는 가상 머신을 만듭니다. 또한 ping 192.168.122.2
위에서 생성된 다른 가상 머신은 다음 명령을 실행한 후에 실행할 수 없습니다.
virt-install --name=private-centos7 --disk path=/var/lib/libvirt/images/guest2.img,size=50 \
--graphics none --vcpus=1 --memory=2048 --location /tmp/CentOS-7-x86_64-Minimal-1611.iso \
--network=default --os-type=linux --os-variant=rhel7.0 --initrd-inject=/tmp/vm.ks \
--extra-args "ks=file:/vm.ks console=ttyS0 ip=192.168.122.2::PUBLIC.IP.OF.GATEWAY:255.255.255.0:localhost2:eth0:none"
virt-install
그러나 위 명령을 실행하면 dmesg
다음 줄이 로그에 추가됩니다.
[94333.242521] systemd[1]: sys-subsystem-net-devices-vnet1.device changed plugged -> dead
[94333.242528] systemd[1]: sys-devices-virtual-net-vnet1.device changed plugged -> dead
[94333.242533] systemd[1]: Collecting sys-devices-virtual-net-vnet1.device
[94333.242534] systemd[1]: Collecting sys-subsystem-net-devices-vnet1.device
dmesg
다른 로그는 실행 중에 기록되지만 virt-install
위의 4줄이 네트워크와 가장 관련성이 높습니다. 만료된 보고서를 처리할 수 있는 방법을 찾아야 합니까 vnet1
? 그렇다면 어떻게 해야 할까요?
default
호스트의 네트워크:다음은 HOST의 네트워크 정의입니다 xml
.default
[root@localhost ~]# virsh net-edit default
<network>
<name>default</name>
<uuid>some-long-complex-string</uuid>
<forward mode='nat'/>
<bridge name='br0' stp='on' delay='0'/>
<mac address='11:22:33:44:55:66'/>
<ip address='192.168.122.1' netmask='255.255.255.0'>
<dhcp>
<range start='192.168.122.2' end='192.168.122.254'/>
</dhcp>
</ip>
</network>
~
~
"/tmp/virshycDOpm.xml" 12L, 347C
다음은 호스트에서 사용 가능한 브리지를 나열하는 출력입니다.
[root@localhost ~]# brctl show
bridge name bridge id STP enabled interfaces
br0 8000.1stStringID no eno1
vnet0
vnet1
virbr0 8000.2ndStringID yes virbr0-nic
[root@localhost ~]#
네트워크 정의가 bridge name
또는 으로 설정되어 있는지 여부에 관계없이 동일한 문제가 여전히 존재합니다. default
xml
virbr0
br0
개인 게스트 구성:
[root@localhost ~]# virsh console public2-centos7
Connected to domain public2-centos7
Escape character is ^]
ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 11:22:33:44:55:66 brd aa:bb:cc:dd:ee:ff
inet 192.168.122.2/29 brd 192.168.122.7 scope global eth0
valid_lft forever preferred_lft forever
inet6 ipv6:addr:does:NOT::matter/128 scope global dynamic
valid_lft 603985sec preferred_lft 603985sec
inet6 ipv6:addr:does:NOT::matter/64 scope global noprefixroute dynamic
valid_lft 2371267sec preferred_lft 297667sec
inet6 ipv6:addr:does:NOT::matter/64 scope link
valid_lft forever preferred_lft forever
[root@localhost ~]# ping 192.168.122.7
Do you want to ping broadcast? Then -b
[root@localhost ~]#
@Christopher의 제안:
@Christopher의 제안에 따라 호스트 시스템에서 다음 명령을 실행했습니다.
[root@remote-host ~]# netstat -anr
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
0.0.0.0 PUBLIC.IP.OF.GATEWAY 0.0.0.0 UG 0 0 0 br0
PUBLIC.IP.OF.HOST-1 0.0.0.0 255.255.255.248 U 0 0 0 br0
192.168.122.0 0.0.0.0 255.255.255.0 U 0 0 0 virbr0
[root@remote-host ~]# vi /etc/iproute2/rt_tables
#
# reserved values
#
255 local
254 main
253 default
0 unspec
#
# local
#
#1 inr.ruhep
~
"/etc/iproute2/rt_tables" 11L, 87C
지정된 목적지는 다음과 같습니다 br0
.하나 미만PUBLIC.IP.OF.HOST
, 이는 공용 IP이지만 우리 인터넷 계정이 주장하는 공용 IP 중 하나가 아님을 의미합니다.
@Christopher의 제안에 따라 다음 /etc/iproute2/rt_tables
과 같이 변경해야 한다고 들었습니다.
#
# reserved values
#
255 local
254 main
253 default
0 unspec
#
# local
#
#1 inr.ruhep
200 mgmt
CentOS 7 서버의 파일이 포함된 디렉터리의 내용은 ifcfg
다음과 같습니다.
[root@remote-host ~]# ls -al /etc/sysconfig/network-scripts
total 256
drwxr-xr-x. 2 root root 4096 Mar 28 08:18 .
drwxr-xr-x. 6 root root 4096 Mar 28 08:18 ..
-rw-r--r--. 1 root root 148 Mar 24 19:39 ifcfg-br0
-rw-r--r--. 1 root root 129 Mar 24 19:36 ifcfg-eno1
-rw-r--r--. 1 root root 12288 Mar 26 13:18 .ifcfg-eno1.swp
-rw-r--r--. 1 root root 254 Sep 12 2016 ifcfg-lo
lrwxrwxrwx. 1 root root 24 Mar 24 19:16 ifdown -> ../../../usr/sbin/ifdown
-rwxr-xr-x. 1 root root 627 Sep 12 2016 ifdown-bnep
-rwxr-xr-x. 1 root root 5817 Sep 12 2016 ifdown-eth
-rwxr-xr-x. 1 root root 6196 Nov 5 18:47 ifdown-ib
-rwxr-xr-x. 1 root root 781 Sep 12 2016 ifdown-ippp
-rwxr-xr-x. 1 root root 4201 Sep 12 2016 ifdown-ipv6
lrwxrwxrwx. 1 root root 11 Mar 24 19:16 ifdown-isdn -> ifdown-ippp
-rwxr-xr-x. 1 root root 1778 Sep 12 2016 ifdown-post
-rwxr-xr-x. 1 root root 1068 Sep 12 2016 ifdown-ppp
-rwxr-xr-x. 1 root root 837 Sep 12 2016 ifdown-routes
-rwxr-xr-x. 1 root root 1444 Sep 12 2016 ifdown-sit
-rwxr-xr-x. 1 root root 1621 Nov 5 18:36 ifdown-Team
-rwxr-xr-x. 1 root root 1556 Apr 15 2016 ifdown-TeamPort
-rwxr-xr-x. 1 root root 1462 Sep 12 2016 ifdown-tunnel
lrwxrwxrwx. 1 root root 22 Mar 24 19:16 ifup -> ../../../usr/sbin/ifup
-rwxr-xr-x. 1 root root 12688 Sep 12 2016 ifup-aliases
-rwxr-xr-x. 1 root root 859 Sep 12 2016 ifup-bnep
-rwxr-xr-x. 1 root root 11880 Sep 12 2016 ifup-eth
-rwxr-xr-x. 1 root root 10145 Nov 5 18:47 ifup-ib
-rwxr-xr-x. 1 root root 12039 Sep 12 2016 ifup-ippp
-rwxr-xr-x. 1 root root 10525 Sep 12 2016 ifup-ipv6
lrwxrwxrwx. 1 root root 9 Mar 24 19:16 ifup-isdn -> ifup-ippp
-rwxr-xr-x. 1 root root 642 Sep 12 2016 ifup-plip
-rwxr-xr-x. 1 root root 1043 Sep 12 2016 ifup-plusb
-rwxr-xr-x. 1 root root 2772 Sep 12 2016 ifup-post
-rwxr-xr-x. 1 root root 4154 Sep 12 2016 ifup-ppp
-rwxr-xr-x. 1 root root 1925 Sep 12 2016 ifup-routes
-rwxr-xr-x. 1 root root 3263 Sep 12 2016 ifup-sit
-rwxr-xr-x. 1 root root 1755 Apr 15 2016 ifup-Team
-rwxr-xr-x. 1 root root 1876 Apr 15 2016 ifup-TeamPort
-rwxr-xr-x. 1 root root 2682 Sep 12 2016 ifup-tunnel
-rwxr-xr-x. 1 root root 1740 Sep 12 2016 ifup-wireless
-rwxr-xr-x. 1 root root 4623 Sep 12 2016 init.ipv6-global
-rw-r--r--. 1 root root 15383 Sep 12 2016 network-functions
-rw-r--r--. 1 root root 26829 Sep 12 2016 network-functions-ipv6
그 내용은 ifcfg-br0
다음과 같습니다.
[root@remote-host ~]# vi /etc/sysconfig/network-scripts/ifcfg-br0
TYPE=Bridge
BOOTPROTO=static
NAME=br0
DEVICE=br0
ONBOOT=yes
DNS1=11.11.11.11
DNS2=11.11.22.22
IPADDR=PUBLIC.IP.OF.HOST
PREFIX=29
GATEWAY=PUBLIC.IP.OF.GATEWAY
~
~
"/etc/sysconfig/network-scripts/ifcfg-br0" 11L, 148C
그 내용은 ifcfg-eno1
다음과 같습니다:
[root@remote-host ~]# vi /etc/sysconfig/network-scripts/ifcfg-eno1
TYPE=Ethernet
BOOTPROTO=static
NAME=eno1
UUID=some-long-complicated-string-here
DEVICE=eno1
ONBOOT=yes
BRIDGE=br0
추가 파일을 추가하고 다른 파일을 수정해야 합니까? 그렇다면 어떻게 해야 할까요?