LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 05-01-2019, 08:40 AM   #1
jhndoe
LQ Newbie
 
Registered: May 2019
Posts: 1

Rep: Reputation: Disabled
Creating a Debian Router from a virtual machine


I am trying to create a router from a Debian machine on virtual box, but I can't get it to work properly. The router has got two network adapters, one that's bridged, and the other is running an internal network.

After setting up the router, I'm unable to retrieve an IP-address from the internal/private interface (eth1), and I can't understand why.

After booting up the machine I configured the networks interfaces as such:

nano -w /etc/network/interfaces

# The external WAN interface (eth0)
allow-hotplug eth0
iface eth0 inet dhcp

# The internal LAN interface (eth1)
allow-hotplug eth 1
iface eth1 inet static
address 192.168.42.1
netmask 255.255.255.0
network 192.168.42.0
broadcast 192.168.42.255

pre-up iptables-restore < /etc/iptables.rules

Then I installed dnsmasq and configured it like this:

nano -w /etc/dnsmasq.conf

interface=eth1
listen-address=127.0.0.1
dhcp-range=192.168.42.100,192.168.42.110,12h


And finally i configured iptables:

nano -w /etc/iptables.rules
*nat
-A PREROUTING -i eth0 -p tcp -m tcp --dport 50000 -j DNAT --to-destination
192.168.0.3:50000
-A POSTROUTING -o eth0 -j MASQUERADE
COMMIT

*filter
-A INPUT -i lo -j ACCEPT
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -i eth0 -p tcp -m tcp --dport 222 -j ACCEPT
-A INPUT -i eth0 -j DROP
-A FORWARD -i eth0 -p tcp -m tcp --dport 50000 -m state --state NEW -j
ACCEPT
COMMIT

After this I activated the iptables rules and rebooted, only to get no IP-adress from eth1.
 
Old 05-01-2019, 01:39 PM   #2
tyler2016
Member
 
Registered: Sep 2018
Distribution: Debian, CentOS, FreeBSD
Posts: 243

Rep: Reputation: Disabled
It looks like you have a space between eth and 1 in the hotplug line of /etc/network/interfaces.

You have:

Code:
allow-hotplug eth 1
where it should be:

Code:
allow-hotplug eth1
You also need to turn on the forwarding kernel parameter. Add net.ipv4.ip_forward=1 to /etc/sysctl.conf and then run this command as root:

Code:
sysctl net.ipv4.ip_forward=1

Last edited by tyler2016; 05-01-2019 at 01:41 PM.
 
Old 05-01-2019, 05:55 PM   #3
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,704

Rep: Reputation: 5897Reputation: 5897Reputation: 5897Reputation: 5897Reputation: 5897Reputation: 5897Reputation: 5897Reputation: 5897Reputation: 5897Reputation: 5897Reputation: 5897
What distribution/version are you running for the client virtual machine?

Is your client vm configured with an internal network?

In your dnsmasq.conf file the listen address should also include your IP address.
listen-address=127.0.0.1,192.168.42.1

You also need to configure gateway:
dhcp-option=3,192.168.42.1
and DNS
dhcp-option=6,192.168.42.1

What iptables rules if any do you have for eth1?
What are the default policies?
 
Old 05-03-2019, 01:53 PM   #4
i2_infinity
LQ Newbie
 
Registered: Jul 2013
Location: India
Distribution: RHEL, Fedora
Posts: 10
Blog Entries: 1

Rep: Reputation: 0
I always use NAT on virtual box, particularly when I am changing locations.

I believe some networks might be restrictive to have the physical network interfaces on the underlying hosts to be available for bridge networks.

Regards.
 
  


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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to : Open Virtual Machine Manager to create a new virtual machine BKChicago Linux - Newbie 2 11-08-2016 09:48 PM
Looking For A Bootable OS + Virtual Machine Combo - Bootable Virtual Machine OS Help angelbabycry Linux - Newbie 7 05-08-2015 08:36 PM
how to know the remote machine is Virtual machine or physical machine pantdk Linux - Server 19 10-16-2014 01:48 PM
Is base memory of virtual machine used when virtual machine is not running? ravisingh1 Linux - Virtualization and Cloud 3 04-09-2013 03:41 AM
Running virtual pc files in a virtual machine in linux ... preferably virtual box biharibong Linux - Software 4 01-21-2009 01:04 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 05:29 AM.

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