Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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:

       (192.168.0.1
    netmask 255.255.255.0)     
ISP --- wireless router --- wlan0 on home (192.168.0.12)
               |             eth0 on home --- MyBookLive
            MacBook
        (192.168.0.11)

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 192.168.0.66
iptables -t nat -A PREROUTING -i eth0 -p udp -j DNAT --to 192.168.0.66

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.

share|improve this question
add comment

3 Answers

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.

#!/bin/sh
INTERNAL_IP=home.lan
INTERNAL_NM=255.255.255.0
INTERNAL=eth0
EXTERNAL=wlan0

ifconfig $INTERNAL $INTERNAL_IP netmask $INTERNAL_NM up

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

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

#(continued)
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; 192.160.0.66)
home.lan (home wlan0 ip address; 192.168.0.12)

References:
http://www.centos.org/docs/4/html/rhel-sg-en-4/s1-firewall-ipt-fwd.html
http://www.netfilter.org/documentation/HOWTO//NAT-HOWTO-6.html#ss6.2

share|improve this answer
add comment

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.

EDIT:

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

share|improve this answer
    
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. –  AcidFlask Dec 9 '12 at 22:30
add comment

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).

interface=wlan0
driver=nl80211
ssid=AcidFlask
channel=9
hw_mode=g
country_code=NO
auth_algs=1
wpa=0
ignore_broadcast_ssid=0

Then I launch the hostapd daemon and forwarding this way:

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

At last, I define a static IP on my client (172.20.99.2 for example, with netmask 255.255.255.0, gateway 172.20.99.1 and DNS 8.8.8.8).

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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