라우팅된 네트워크를 사용하여 libvirt VM에 콘센트 IP 할당

라우팅된 네트워크를 사용하여 libvirt VM에 콘센트 IP 할당

내 호스트 네트워크 인터페이스에는 두 개의 IP가 있습니다. 현재 저는 VM을 실행하고 있습니다.라우팅됨회로망.

public호스트의 네트워크 인터페이스는 의 영역 구성원이며 firewalld, 둘 다앞으로그리고가장 무도회활성화되었습니다.

앞에서 설명한 설정을 사용하면 VM이 인터넷에 연결될 수 있고 의 를 사용하여 VM에 포트 전달을 추가할 수 firewalld있습니다 --add-forward-port.

하지만 이제 내 VM의 콘센트 IP 중 하나(해당 IP)를 변경하고 싶습니다.가장 무도회to) 내 호스트의 네트워크 인터페이스에서 사용 가능한 다른 IP로. 에서는 이를 지원하지 않기 때문에 규칙
을 추가하려고 했습니다 . 내가 사용한 명령은 VM의 인터넷 연결이 끊어지지만 에 설정된 포트 전달을 사용하여 계속 연결할 수 있다는 것입니다 .SNATnftablesfirewalldnft add rule nat POSTROUTING snat to ip saddr map { <VM's IP> : <public ip> }firewalld

이에 대해 Google에서 검색했지만 이에 대한 정보를 많이 찾지 못했습니다.

다음은 몇 가지 구성입니다.

기본 공용 IP는 으로 수정되고 10.0.0.1, 보조 공용 IP는 로 수정됩니다 10.0.0.2.

VM 1의 NAT IP는 로 수정되고 192.168.122.1, VM 2의 NAT IP는 로 수정됩니다 192.168.122.2.

방화벽D

libvirt (active)                                                                                                                                                                                                                                                                                                                                         
  target: ACCEPT                                                                                                                                                                                                                                                                                                                                         
  icmp-block-inversion: no
  interfaces: virbr0
  sources: 
  services: custom--ms-wbt-server-ms-wbt-server dhcp dhcpv6 dns ssh tftp
  ports: 
  protocols: icmp ipv6-icmp
  forward: no
  masquerade: no
  forward-ports: 
  source-ports: 
  icmp-blocks: 
  rich rules: 
        rule priority="32767" reject

public (active)
  target: default
  icmp-block-inversion: no
  interfaces: enp1s0f0
  sources: 
  services: cockpit dhcpv6-client libvirt libvirt-tls mdns ssh steam-streaming vnc-server
  ports: 
  protocols: 
  forward: yes
  masquerade: yes
  forward-ports: 
  source-ports: 
  icmp-blocks: 
  rich rules: 
        rule family="ipv4" destination address="10.0.0.2" forward-port port="33412" protocol="tcp" to-port="3389" to-addr="192.168.122.2" # another public ip is the ip that i want to change to
        rule family="ipv4" destination address="10.0.0.1" forward-port port="33411" protocol="udp" to-port="3389" to-addr="192.168.122.1" # default public ip is the default outlet ip
        rule family="ipv4" destination address="10.0.0.1" forward-port port="33411" protocol="tcp" to-port="3389" to-addr="192.168.122.1"
        rule family="ipv4" destination address="10.0.0.2" forward-port port="33412" protocol="udp" to-port="3389" to-addr="192.168.122.2"

버쉬

<network connections='2'>
  <name>default</name>
  <uuid>(network uuid)</uuid>
  <forward mode='route'/>
  <bridge name='virbr0' stp='on' delay='0'/>
  <mac address='<mac address>'/>
  <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>

ip addr

enp1s0f0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether <mac address> brd ff:ff:ff:ff:ff:ff
    inet 10.0.0.1/24 brd <broadcast addr> scope global noprefixroute enp1s0f0
       valid_lft forever preferred_lft forever
    inet 10.0.0.2/25 brd <broadcast addr> scope global noprefixroute enp1s0f0
       valid_lft forever preferred_lft forever

ip route

default via <default public ip gateway> dev enp1s0f0 proto static metric 100 
<default public ip subnet> dev enp1s0f0 proto kernel scope link src 10.0.0.1 metric 100 
<secondary public ip subnet> dev enp1s0f0 proto kernel scope link src 10.0.0.2 metric 100 
<virsh network subnet> dev virbr0 proto kernel scope link src 192.168.122.1

내 서버가 및 Fedora 37으로 실행 중입니다 .firewalld 1.2.2nftables 1.0.4

관련 정보