LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Virtualization and Cloud
User Name
Password
Linux - Virtualization and Cloud This forum is for the discussion of all topics relating to Linux Virtualization and Linux Cloud platforms. Xen, KVM, OpenVZ, VirtualBox, VMware, Linux-VServer and all other Linux Virtualization platforms are welcome. OpenStack, CloudStack, ownCloud, Cloud Foundry, Eucalyptus, Nimbus, OpenNebula and all other Linux Cloud platforms are welcome. Note that questions relating solely to non-Linux OS's should be asked in the General forum.

Notices


Reply
  Search this Thread
Old 03-05-2021, 06:40 AM   #1
n00b_noob
Member
 
Registered: Sep 2020
Posts: 436

Rep: Reputation: Disabled
Post How to ping a VM from the host with NAT settings?


Hello,
I installed a Linux distro in the VirtualBox and my VM network settings is NAT. I know that with the NAT setting, my VM can ping the host OS, but host OS can't ping the VM. My VM IP address is "10.0.2.15".
Any solution for it that my host can see the VM with NAT settings?

Thank you.
 
Old 03-05-2021, 07:33 AM   #2
tinfoil3d
Member
 
Registered: Apr 2020
Location: Japan/RJCC
Distribution: debian, lfs, whatever else i need in qemu
Posts: 268

Rep: Reputation: 75
Not sure there is a way. It's on different networks anyway, even if that would have been theoretically possible. Host doesn't see that NAT network because it's not even a network for the host kernel, and VM kernel is on that "host-virtual" network. If I want to connect sshd on guest but still use NAT I would create "host-only" NIC as secondary NIC and assign some known IP there in guest and then connect that via vboxnet0 on host.
 
1 members found this post helpful.
Old 03-05-2021, 07:39 AM   #3
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,701

Rep: Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895
Not with ping. NAT works just like a home router. If you want to access a VM using NAT from the host you need to forward the desired port.

There are other network modes that can directly access the host but it depends on what you are trying to accomplish.
 
1 members found this post helpful.
Old 03-05-2021, 10:58 AM   #4
n00b_noob
Member
 
Registered: Sep 2020
Posts: 436

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by tinfoil3d View Post
Not sure there is a way. It's on different networks anyway, even if that would have been theoretically possible. Host doesn't see that NAT network because it's not even a network for the host kernel, and VM kernel is on that "host-virtual" network. If I want to connect sshd on guest but still use NAT I would create "host-only" NIC as secondary NIC and assign some known IP there in guest and then connect that via vboxnet0 on host.
Thanks.
You can use port forwarding with NAT and SSH to your VM.
 
Old 03-05-2021, 11:04 AM   #5
n00b_noob
Member
 
Registered: Sep 2020
Posts: 436

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by michaelk View Post
Not with ping. NAT works just like a home router. If you want to access a VM using NAT from the host you need to forward the desired port.

There are other network modes that can directly access the host but it depends on what you are trying to accomplish.
Thank you.
My real goal is to make an Apache lab:
Code:
Host --> VM1 (Reverse Proxy) --> VM2 (Apache Server)
I want to connect to the Apache Server (VM2) from the host machine through the Reverse Proxy (VM1) . Which network settings are good for VM1 and VM2? For example, the network settings for VM1 must be "NAT" or "Internal Network"?
 
Old 03-05-2021, 07:29 PM   #6
berndbausch
LQ Addict
 
Registered: Nov 2013
Location: Tokyo
Distribution: Mostly Ubuntu and Centos
Posts: 6,316

Rep: Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002
Quote:
Originally Posted by n00b_noob View Post
Code:
Host --> VM1 (Reverse Proxy) --> VM2 (Apache Server)
I want to connect to the Apache Server (VM2) from the host machine through the Reverse Proxy (VM1) .
Port forwarding works for other ports than 22. You can access VM1 from host by forwarding whatever port the proxy server listens on.

If both VM1 and VM2 are NAT'ed, I doubt there is a way to connect them directly. It's easiest if they are on the same network. Perhaps NAT Network is best in this case. Of course, bridging removes all these problems.
 
1 members found this post helpful.
Old 03-06-2021, 07:57 AM   #7
n00b_noob
Member
 
Registered: Sep 2020
Posts: 436

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by berndbausch View Post
Port forwarding works for other ports than 22. You can access VM1 from host by forwarding whatever port the proxy server listens on.

If both VM1 and VM2 are NAT'ed, I doubt there is a way to connect them directly. It's easiest if they are on the same network. Perhaps NAT Network is best in this case. Of course, bridging removes all these problems.
I want my host OS can't see VM2 directly, but VM1 can.
 
Old 03-06-2021, 11:49 AM   #8
berndbausch
LQ Addict
 
Registered: Nov 2013
Location: Tokyo
Distribution: Mostly Ubuntu and Centos
Posts: 6,316

Rep: Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002
Quote:
Originally Posted by n00b_noob View Post
I want my host OS can't see VM2 directly, but VM1 can.
See table 6.1.

Connect both VMs to an internal network. Connect VM1 to any other network type with a second NIC.
 
1 members found this post helpful.
Old 03-06-2021, 12:49 PM   #9
n00b_noob
Member
 
Registered: Sep 2020
Posts: 436

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by berndbausch View Post
See table 6.1.

Connect both VMs to an internal network. Connect VM1 to any other network type with a second NIC.
Thanks.
I set two NICs for my VM1. One is "NAT" and another one is "Internal Network".
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
guset can ping the host but host can't ping the guest . linuxreza Linux - Newbie 1 07-28-2012 02:47 PM
Forwarding ping packets from one 1st host to 2nd host via 2rd host sachee Linux - Networking 1 09-25-2011 01:51 PM
I cannot ping with command 'ping IP' address but can ping with 'ping IP -I eth0' sanketmlad Linux - Networking 2 07-15-2011 05:32 AM
NAT and NAT Server behind its own NAT(private network) zeusys Linux - Networking 1 06-08-2011 06:22 PM
ping works, host works, ping host does not dublin212 Linux - Networking 3 03-31-2003 11:38 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Virtualization and Cloud

All times are GMT -5. The time now is 04:37 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration