Project Home
Project Home
Wiki
Wiki
Discussion Forums
Discussions
Project Information
Project Info
Forum Topic - Setting up a device as Router: (4 Items)
   
Setting up a device as Router  
I have a device. This has 2 NIC on it. I have named them en0 and en1. 
en1 is connected to network and I have a dhcp client running that can fetch address for this interface. en0 is connected
 another device that has a dhcp client. Sample output from ifconfig:
# ifconfig
lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> mtu 33192
        inet 127.0.0.1 netmask 0xff000000
en1: flags=8b43<UP,BROADCAST,RUNNING,PROMISC,ALLMULTI,SIMPLEX,MULTICAST> mtu 1500
        address: 00:16:80:00:7a:d3
        media: Ethernet autoselect (100baseTX full-duplex)
        status: active
        inet 10.11.148.225 netmask 0xfffffe00 broadcast 10.11.149.255
en0: flags=80008902<BROADCAST,PROMISC,SIMPLEX,MULTICAST,SHIM> mtu 1500
        address: 48:f8:b3:2b:20:d5
        media: Ethernet 100baseTX full-duplex
        status: active

What I want to do is make this device that has 2 interfaces to act as a router and route all the packets arrivinf at en0
 to en1 and vice vers, so that for the device connected to en0 it should seem as if it is on the network on en1.

Note that the dhcp server is somewhere on the network connected to en1.

I also went through the concept of hub/switch. Is there a way to configure my device as a hub so that all the packets 
received on en0 are echoed on en1 and vice versa?

Am I missing anything concept wise?
		
Re: Setting up a device as Router  
There are three different solutions and I'm not sure on which you need based on your post.

1) Act as a bridge. This means that the DHCP client on devices connected to en0 will get the configuration from the DHCP
 server on a device on en1. This is what I think you are looking for based on your comments. In this case you would "
ifconfig bridge0 create" and then add in the two interfaces to the bridge and configure the bridge with "brconfig" 
commands.

2) Act as a router. In this case you would have two separate subnets on en0 and en1 and would forward IP packets between
 them. You would have to run your own DHCP server for devices on en0 and ensure that your en1 is known as the route to 
access the en0 subnet. In this case you would need to use "sysctl" to set "net.inet.ip.forwarding" to 1.

3) Act as a NAT router. This would require again setting up as a DHCP server for devices on en0, but by loading the pf 
module and configuring pf rules you would make the packets received on en0 look as if they were coming from you on en1 
so the rest of the world doesn't need to know that en1 is the route to access the en0 subnet.
Re: Setting up a device as Router  
yes acting as a bridge is what I am looking at and have tried too. That is why the promiscous mode is on. But I am not 
sure why the packets are not getting through?!

%%%%%%%%%%%%%%%	START io-pkt	%%%%%%%%%%%%%%%
# io-pkt-v4-hc -v -d ep93xx -d asix -t2 &

%%%%%%%%%%%%%%%	configure bridge	%%%%%%%%%%%%%%%
# ifconfig bridge0 create
# brconfig bridge0 add en1 add en0 up
# brconfig -a
bridge0: flags=41<UP,RUNNING>
        Configuration:
                priority 32768 hellotime 2 fwddelay 15 maxage 20
                ipfilter disabled flags 0x0
        Interfaces:
                en0 flags=3<LEARNING,DISCOVER>
                        port 3 priority 128
                en1 flags=3<LEARNING,DISCOVER>
                        port 2 priority 128
        Address cache (max cache: 100, timeout: 1200):
		
%%%%%%%%%%%%%%%	start dhcp client for en1	%%%%%%%%%%%%%%%

# dhcp.client -i en1 &
# ifconfig
lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> mtu 33192
        inet 127.0.0.1 netmask 0xff000000
en1: flags=8b43<UP,BROADCAST,RUNNING,PROMISC,ALLMULTI,SIMPLEX,MULTICAST> mtu 1500
        address: 00:16:80:00:7a:d3
        media: Ethernet autoselect (100baseTX full-duplex)
        status: active
        inet 10.11.148.225 netmask 0xfffffe00 broadcast 10.11.149.255
en0: flags=80008902<BROADCAST,PROMISC,SIMPLEX,MULTICAST,SHIM> mtu 1500
        address: 48:f8:b3:2b:20:d5
        media: Ethernet 100baseTX full-duplex
        status: active
bridge0: flags=41<UP,RUNNING> mtu 1500
# 


Re: Setting up a device as Router  
You need to bring up en0 with "ifconfig en0 up". Interface en1 was brought up by the dhcp.client, but en0 is still down.