LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How to access VM's address from host computer? (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-access-vms-address-from-host-computer-4175586621/)

fanoflq 08-08-2016 08:34 PM

How to access VM's address from host computer?
 
How to access VM's address from host computer?
Scenario:

Hostname: LinuxMint

Quote:

Virtual machine: KVM, CentOS7
#Look at address on interface of VM
[user1@localhost html]$ ifconfig
ens3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.122.216 netmask 255.255.255.0 broadcast 192.168.122.255
I have installed httpd.
From within the CentOS7 VM, I am able to display index.html in Firefox using url http://localhost or http://192.168.122.216/


Quote:

# I am also able to ping http://192.168.122.216/ from the host to VM.
LinuxMint $ ping 192.168.122.216
PING 192.168.122.216 (192.168.122.216) 56(84) bytes of data.
64 bytes from 192.168.122.216: icmp_seq=1 ttl=64 time=0.792 ms
64 bytes from 192.168.122.216: icmp_seq=2 ttl=64 time=0.613 ms
... ...
But I cannot display the webpage index.html from LinuxMint host (not from the CentOS VM) using Firefox, using url http://http://192.168.122.216/

I can ping the VM's address from host, but not display its web page.
Why?
Is there a way to do this?

Alternatively, if my host IP address is 192.168.0.14,
I can ping it also from the VM's side:
But not able to access index.html on host side with Firefox via http://192.168.0.14.

frankbell 08-08-2016 08:38 PM

A couple of questions for starters:

Is port 80 open to external calls in the VM? (That's the default port for www.)

Can you ssh into the VM?

fanoflq 08-08-2016 08:54 PM

@frankbell:

Here is the address : port setting in httpd.conf:
Quote:

#
# Listen: Allows you to bind Apache to specific IP addresses and/or
# ports, instead of the default. See also the <VirtualHost>
# directive.
#
# Change this to Listen on specific IP addresses as shown below to
# prevent Apache from glomming onto all bound IP addresses.
#
#Listen 12.34.56.78:80
#Listen 80 # this did not work earlier
Listen 192.168.122.216:80
Still not able to access VM's index.html from host side.

chrism01 08-08-2016 11:38 PM

Run
Code:

iptables -nvL
on VM to chk firewall.

Also
Code:

netstat -tanp
also on VM to chk httpd IS listening

fanoflq 08-08-2016 11:51 PM

I am using CentOS7, and firewalld is running.
So I cannot run iptables due to conflicts.

Quote:

[user1@localhost ~]$ netstat -tanp
(Not all processes could be identified, non-owned process info
will not be shown, you would have to be root to see it all.)
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 192.168.122.216:80 0.0.0.0:* LISTEN -
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN -
tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN -
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN -
... ...
Quote:

[user1@localhost ~]$ firewall-cmd --get-active-zones
public
interfaces: ens3
[user1@localhost ~]$ ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
... ...
2: ens3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 52:54:00:d4:63:70 brd ff:ff:ff:ff:ff:ff
inet 192.168.122.216/24 brd 192.168.122.255 scope global dynamic ens3
valid_lft 2520sec preferred_lft 2520sec
inet6 fe80::5054:ff:fed4:6370/64 scope link
valid_lft forever preferred_lft forever

As you can see tcp is listening on 192.168.122.216 : 80.
And the address corresponds to interface inet 192.168.122.216/24.

chrism01 08-08-2016 11:53 PM

well, use whatever C7 cmd is equiv; you need to chk if firewall is open...

fanoflq 08-09-2016 12:53 AM

@chrism01:

Thanks.
I turned off firewalld on port, and it worked.

Quote:

firewall-cmd --zone=public --add-port=80/tcp


All times are GMT -5. The time now is 07:43 AM.