4

I have an archlinux machine setup a Windows 7 virtual machine using qemu. Network Source: NAT/ Device Model:virtio is the networking configuration for NATing. I am able to connect to the Internet just fine.

However, how do I connect to the host machine itself using IP? Actually, I want to access the webserver running in the host machine on multiple ports!

I tried opening the ipconfig's gateway which is 192.168.122.1 but that is not connecting to the nginx I am running on my host. For example http://192.168.122.1 doesn't bring up the nginx nor another webserver I run at another port. tracert is also not helping me much.

Indeed 192.168.122.1 is the vibr0 in my host and this is the gateway of the virtual machine.

5
  • 1
    Specify your distribution and version! On Fedora, you have to enable the port in the firewall.
    – sourcejedi
    Commented Jun 26, 2017 at 16:35
  • 1
    After a connection attempt, ip neigh on the host should show an entry, for the IP address of the VM. (You can probably use ip -4 neigh, if you're not using a v6 address).
    – sourcejedi
    Commented Jun 26, 2017 at 16:40
  • 1
    Depending on your configuration your host's address is the same as the default router (e.g. 192.168.122.1, if you did not modify).
    – ridgy
    Commented Jun 26, 2017 at 22:21
  • @sourcejedi, pardon my ignorance but on the host of client side!
    – Nishant
    Commented Jun 27, 2017 at 5:47
  • 1
    Firewall would be on server (nginx) side. I guess you'd remember if you had one on arch :). ip -4 neigh show dev virbr0 on host after connection attempt please, and/or tcpdump -i virbr0 during.
    – sourcejedi
    Commented Jun 27, 2017 at 7:13

2 Answers 2

3

virt-manager needs firewalld.service to be up and running in the host machine. This will disable all the ports from external access by default. So we need to explicitly enable the ports that need to be accessed in the host machine. Assuming you want to enable the port 8000, here are the commands you need to execute in the host machine:

sudo firewall-cmd --permanent --add-port=8000/tcp
sudo firewall-cmd --reload

Here is the source of this answer.

1

I use firewall-config, the GUI for firewalld, which handles editing rules and making them permanent, so I don't have to worry about it. I highly recommend it.

I simply had to do one thing:

  • Go into the zone named libvirt in the Firewalld GUI.
  • Go to the "Ports" tab.
  • Add a port, such as tcp 5000.

Now my virtual machine can connect to the host machine's IP on port 5000. :)

This technique ensures that the port only opens on the virtual machine's network, not all networks!

You can use the host machine's normal ethernet IP when connecting to it from the guest, by the way.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .