Based on this question can the following be done:

 - Router with DHCP connected to NIC A on Box 1
 - Machine B connected to NIC B on Box 1

I need Machine B to get a DHCP IP address from the Router on NIC A. Currently the setup and configuration is as follows:

 - NIC A DHCP Assigned IP: 10.0.x.x (
 - NIC B Static IP: 10.1.x.x (

I have ipv4_forwarding on however I can't assign a static IP to the Machine B. What do I need to do to get all traffic from NIC A to flow through NIC B. Or more specifically how can I get Machine B to get an IP address from the DHCP on the router.

  • Do I need to setup IPTables? If so where do I start?
  • Do I need to setup a route on the linux box? How?
  • It can't be done?

To Clarify

This box is NOT the router. There is already a router in place. This is a linux box used for Samba Shares and Virtual Machines. There is however some machines that can't be connect to the main switch, however they can be connected through another hub to this machine.

In Short This machine is sitting in the middle.


You've got three hosts:

Machine "B" ======  Machine "A" ====== Machine "R"    

Unless Machine "R" (your router) knows that routes through it simply will not work.

You have three choices:

  1. Create a bridge on Machine "A"
  2. Get Machine "R" to install a routing table and use a combination of ICMP redirect and proxy_arp to configure the rest of the network
  3. Use Network Address Translation on Machine "A". This will "hide" all of the hosts to the left of it, so machine "R" will not be able to access services on Machine "B".

To create a bridge, is really straightforward. On Machine "A":

brctl addbr br0
brctl addif br0 eth0
brctl addif br0 eth1
brctl stp br0 on

Then configure br0 to have the IP address that you want to have (say by running dhclient br0).

Then, Machine "B" should be able to use dhclient eth0 and get an IP address from Machine "R"

Bridges come with a whole bunch of problems, not the least of which being the fact that a lot of devices have buggy STP support.

If you get Machine "R" to create your routing table, you'll need Machine "A" to enable proxy arp:

echo 1 > /proc/sys/net/ipv4/conf/all/proxy_arp

Other machines on your network will need to accept ICMP redirects. I've seen at least two printers that don't by default. Your mileage may vary.

Finally, enabling Network Address Translation is really a simple matter of:

iptables -t nat -A POSTROUTING -s -j SNAT --to-source $IP

where $IP is the address given by Machine "R" for use. There are a number of tools that automate this.


You should bridge the two network interfaces; this way, the middle computr will act just like a network hub, passing traffic between the two ports in a completely transparent way. No routing, no configurations to do, the other computer and the router will "just" be able to talk to each other (and to the bridging computer, of course).

  • Thanks. This looks like the way to go. I have found a tutorial on setting up bridging, once I have it working I will provide feedback. – BinaryMisfit Sep 1 '09 at 19:00

You need to configure DHCP Relay Agent in your linux box. The DHCP Relay Agent allows you to relay DHCP request from one subnet to other DHCP servers in different subnets. The linux command to do DHCP relay is dhcrelay

Also you need to check if you can reach the DHCP server from Machine B (check my answer to your other question to configure routes and default gateway) and that no firewall rules in your server are blocking packets from Machine B to the DHCP server.


Why do not bind dhcp server on both interfaces instead ?

by default dhcpd should already listen on every interface (if no parameter is given to the daemon)... so I guess you have only to change your dhcpd.conf in order to manage the netmask on eth1 too ... and the daemon will serve on this interface too.

EDIT after Diago reply Sorry I have misunderstood your question. I don't delete the answer for others reference if useful.

  • The DHCP is on a router connected to the machine, not on the machine itself. – BinaryMisfit Sep 1 '09 at 17:40
  • Perhaps you should setup a DHCP server on the machine with two interfaces. – Zoredache Sep 1 '09 at 18:01
  • The latter is not an option as there is already a fully configured ipCop box handling all the connectivity and routing. – BinaryMisfit Sep 1 '09 at 19:01

If you followed the directions on the question you linked to then the box is a router. The ip_forward = 1 setting enables routing. If that is not what you want, then you'll need to set it up as a bridge.

By having the box setup as a router you are making things more complex then it sounds like you want/need. Configuring the system with two interfaces as a bridge is probably the easiest option. If you need the box to actually be a router then you'll have to consider the other options.

You could setup a dhcp relay agent on the computer, but you will also need to add a route to your router so it can access the inside address space, and you will need to add an additional scope to the router for the internal address space.

You could simply setup a DHCP server on the box with two interfaces and serve the addresses to your inside network. This may be the simplest thing to setup if simply making box with two interfaces a bridge isn't an option.

  • I have updated the question to reflect more details, however bridging seems to be the way to go – BinaryMisfit Sep 1 '09 at 18:59

Box 1 needs to be set up as a dhcp relay agent.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.