# [solved] eth0:dhcp&eth1 : local & use eth1 for VirtualBox ?

## Gregoire

Hello,

under https://forums.gentoo.org/viewtopic-t-804061-highlight-.html I managed to use my eth0 and eth1 more or less like I wanted to  :Smile: 

IP1 and IP2 are public IP I have access to (dhcp).

( "eth0 dhcp IP1" )

( IP2--"router 192.168.7.1" <-> "eth1 fix 192.168.7.2" )

Which is done with (/etc/conf/net) :

```

modules_eth0="!plug"

modules_eth1="!plug"

config_eth0=( "dhcp" )

dhcpcd_eth0="-t 10"

dhcp_eth0="release nontp nonis"

config_eth1=( "192.168.7.2 netmask 255.255.255.0 brd 192.168.7.255" )

```

With that I can use all services on the router under my PC : great.

Now I would like to use eth1 under VirtualBox such that all traffic from VirtualBox

are routed through IP2 (and the traffic from the non emulated PC still remain under

IP1).

Is that possible ?

Thank you very much !Last edited by Gregoire on Sun Dec 27, 2009 2:16 pm; edited 1 time in total

----------

## gentoo_ram

You don't need an ethernet interface to do this.  You'd use a Host-only Interface in Virtualbox.  You get that by loading the Virtualbox host modules.   It just be another interface on your system,  like this:

```
vboxnet0  Link encap:Ethernet  HWaddr 0a:00:27:00:00:00  

          inet addr:192.168.4.1  Bcast:192.168.4.255  Mask:255.255.255.0

          inet6 addr: fd05:efbb:4a1b:4:250:8dff:fe9f:19f4/64 Scope:Global

          inet6 addr: fe80::800:27ff:fe00:0/64 Scope:Link

          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

          RX packets:0 errors:0 dropped:0 overruns:0 frame:0

          TX packets:846826 errors:0 dropped:0 overruns:0 carrier:0

          collisions:0 txqueuelen:1000 

          RX bytes:0 (0.0 B)  TX bytes:432159404 (412.1 MiB)
```

Then configure your virtual machines to use host-only network vboxnet0.  You can connect as many Virtualboxes you want to that network interface.  Another alternative is to bridge the virtual machines to eth1.  But you don't really need to do this.  You configure the vboxnet0 interface IP address using the Virtualbox user interface.

----------

## Gregoire

All try made with this resulted in traffic being sent through eth0 (IP1) how do you set it up right ?

----------

## Exil

you should bridge virtualbox interfaces with eth1.

```

#the interface is really replaced by br0 for outgoing, so if you had dhcp here, you'll use dhcp in br0

config_eth1=( "null" )                                                                                

#this specifies that interface vbox0 will be a tap interface and use the tunctl command to generate itself

tuntap_vbox0="tap"                                                                                                                                                                     

#ALL interfaces part of a bridge should be null, otherwise oddities may occur.

config_vbox0=( "null")                                                        

# you can specify an owner of the interface if you want to run virtual box as a non root user

# [COMMENT from a reader: VirtualBox should never be run as root]

tunctl_vbox0=("-u <yourusername>")

#If you'd prefer a dynamic ip address for the machine, use

config_br1="dhcp"

dhcp_br1="nodns"

#this specifies the bridging information

bridge_br1="eth1 vbox0"

#Make sure your baselayout is recent enough to support this

depend_br1()

{

         need net.eth1

         need net.vbox0

}

brctl_br1=( "setfd 0")

```

also you need net-misc/bridge-utils and sys-apps/usermode-utilities

----------

## Gregoire

Oh nice, should I keep something about :

```

config_eth1=( "192.168.7.2 netmask 255.255.255.0 brd 192.168.7.255" )

```

before or after your ligns ?

Under http://fr.gentoo-wiki.com/wiki/VirtualBox they show an example with:

```

#If you'd prefer a dynamic ip address for the machine, use

#config_br0=( "dhcp" )

config_br0=( "192.168.1.2 netmask 255.255.255" )

routes_br0=( "default via 192.168.1.1" ) 

```

But if I add the "default via 192.168.1.1" then all my traffic goes through eth1...

Thank you very much

----------

## Gregoire

I figured it out using two dhcpcd (static ip for br1 put into /etc/dhcpcd.conf).

Thank you very much !!!

----------

