I inherited an old Linux box as well as a MyBookLive and would like to make the MyBookLive available over my wireless, essentially using the Linux box as a gateway.

I just wiped the Linux box (home) and installed Ubuntu 12.04 on it. My network setup currently looks like this:

ISP --- wireless router --- wlan0 on home (
               |             eth0 on home --- MyBookLive

so that the MyBookLive is basically a glorified external hard drive. The router does have an Ethernet port, but it is being used by my roommate's computer so I can't plug the MyBookLive directly into it.

Right now I can ping MyBookLive.local and MacBook.local from home, but I am having trouble understanding and figuring out what the correct iptables commands are to make my MacBook see my MyBookLive through the Bonjour network. Also, I'm not sure if I need to set up DNS to forward xxx.local Bonjour/Zeroconf addresses.

I tried the following to forward my entire wired network (which has only my MyBookLive) to a single IP address:

sysctl net.ipv4.ip_forward=1
iptables -A FORWARD -i wlan0 -o eth0 -j ACCEPT
iptables -A FORWARD -i eth0 -o wlan0 -j ACCEPT
iptables -t nat -A PREROUTING -i eth0 -p tcp -j DNAT --to
iptables -t nat -A PREROUTING -i eth0 -p udp -j DNAT --to

but I can't ping this address from my MacBook. This is probably horribly wrong, but I am a complete noob at setting up this kind of network and could use some expert help with setting this up properly.


The easiest thing to do here would be setting up a NAT and forwarding the required ports from the wlan0 interface of home to the equivalent ports on the interface of the external hard drive.

The following script is an example that would set up NAT such that the devices connected to eth0 on home (via a switch or a cross-over TP) would gain access to the wireless network.



echo 1 >/proc/sys/net/ipv4/ip_forward
iptables -t nat -A POSTROUTING -o $EXTERNAL -s -j MASQUERADE
iptables -A FORWARD -i $EXTERNAL -o $INTERNAL -m state \

For the described situation to work, devices from the wireless network must be enabled to "look back" into the NAT'ed network (which is hidden behind home.lan). The approach you tried in the question is basically correct, except it translates in the wrong direction. You want to forward packets incoming at specific ports on the home.lan interface into the local hidden NAT'ed ip of mbl.lan

iptables -t nat -A PREROUTING -i $EXTERNAL -p tcp --dport 445 -j DNAT \
      --to mbl.lan:445
iptables -t nat -A PREROUTING -i $EXTERNAL -p tcp --dport 139 -j DNAT \
      --to mbl.lan:139

This setup would make it impossible to run a samba server on the home host, because traffic coming to the default samba ports is sent to the external hard drive. This is not part of the question, but a possible solution would be to run the samba service of home on a different port, or to use a --dport value such as 4455 and manually setting up the clients to connect to a different port when accessing my book live.

Note that this answers assumes samba is being used on the drive and that the ports will need adjusting if a different protocol is used.

A notable limitation of this method is that all connections coming to the external drive will look like they originated at home.lan.

Network aliases:
mbl.lan (my book live ip address;
home.lan (home wlan0 ip address;



I think that simple solution is to set up bridge device br0 on linux-box and add interfaces eth0 and wlan0 to it.

  1. Download bridge-utils on ubuntu
  2. Add bridge brctl addbr br0
  3. Add network devices to bridge brctl addif br0 eth0 and brctl addif br0 wlan0
  4. Set IP to your br0 interface (don't set IPs to eth0 or wlan0)
  5. Delete that DNAT rules from iptables
  6. Edit your iptables config, and replace parameters -i and -o with -m physdev --physdev-in and -m physdev --physdev-out

This'll create virtual br0 interface, that acts as if both wlan0 and eth0 were one interface on one network. That allows you to access your network disk from any pc from your network.


This Is working if you are using your wlan0 as AP in master mode. I suppose you're using hostapd to create that AP on linux-box.

Another thing I should mention is that adding wlan0 interface in my case is possible only after I exec hostapd first.

Great resource to hostapd and linux wireless networking: http://linuxwireless.org/en/users/Documentation/hostapd

  • Have you actually tried this with a wireless card? Please name one ore more wireless cards (drivers) that support this. Dec 4 '12 at 4:19
  • Well, yes I somethimes using this to connect my phone to networks without wifi. My wifi card is Intel Centrino Advanced-N 6205. I also use hostapd, which I should mention in my post and my wlan0 is set in master mode.
    – week
    Dec 4 '12 at 21:33
  • I agree that this should be the right way to do it. I have tried the bridging method previously but my horrible integrated wifi card did not support master mode. Dec 9 '12 at 22:30

I have a similar setup for short-term testing.

Install hostapd this way: (hostapd is a wireless accesspoint daemon)

sudo apt-get install hostapd

Here is a really minimal hostapd.conf config file (note that you will need more config to protect your network with WPA/WPA2).


Then I launch the hostapd daemon and forwarding this way:

sysctl net.ipv4.ip_forward
sysctl -w net.ipv4.ip_forward=1
ifconfig wlan0 netmask
iptables -t nat -A POSTROUTING -s -o eth0 -j MASQUERADE
hostapd -d hostapd.conf

At last, I define a static IP on my client ( for example, with netmask, gateway and DNS

This really is a barebone solution, as it lacks wireless security and DHCP, but it should work and you can build depending on your needs on top of this.

Also note that this solution requires your wifi adapter to support AP mode:

  • ath9k will work in most cases
  • rtl8187 will not work AFAIK

EDIT: I misunderstood your phrase "using the Linux box as a wireless access point". I thought you wanted to connect your Linux box to your MyBookLive wirelessly. Please disregard my solution.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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