Amendements to TVRouter article of July 2013

One of the first articles I wrote on this site concerned using a Raspberry Pi to act as a wifi to ethernet router to enable my (then) TV set to connect to the internet via my main WiFi router. The tv set had an ethernet port, but it was not convenient to wire it to the router by cable. It turned out to be the second most popular post I have written, and has attracted many comments since it was first written in July 2013. Since then the Raspian distro has been improved and altered quite a bit.
Recently I received a comment from a reader who was having problems getting the project to work on the latest distro, and since I had not looked at it for some time, I decided to try a fresh install (on a Pi2) using the latest distro available. Sure enough I found that I too had problems. It appeared that the wlan0 interface did not initialise correctly.
I did some research on the internet and came across an interesting article at http://raspberrypi.stackexchange.com/questions/9678/static-ip-failing-for-wlan0 which appeared to be very relevant. I tried out the wlan0-restart script which was one of the suggested solutions and found that it cured the problem.

I reproduce the script here

 #!/bin/sh
#
#

### BEGIN INIT INFO
# Provides:          wlan0-restart
# Required-Start:    $network
# Required-Stop:     $network
# Should-Start:
# Should-Stop:
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Restarts wlan0 interface
# Description:       Restarts wlan0 interface to fix problem with static address in WiFi AP
# X-Start-Before:    hostapd isc-dhcp-server
### END INIT INFO

PATH=/sbin:/usr/sbin:$PATH

do_start() {
  ifdown wlan0
  ifup wlan0
}

case "$1" in
  start)
    do_start
    ;;
  restart|reload|force-reload)
    echo "Error: argument '$1' not supported" >&2
    exit 3
    ;;
  stop)
    ;;
  status)
    ;;
  *)
    echo "Usage: $0 start|stop" >&2
    exit 3
    ;;
esac
exit 0

To set this up, use the nano editor and create the file
sudo nano /etc/init.d/wlan0-restart
with the content above.
You should then set it to be executable
sudo chmod 755 /etc/init.d/wlan0-restart
It is important that this is executed BEFORE the isc-dhcp server is started
so to ensure that this is the case, if you have already installed isc-dhcp-server as per the original article, you should first disable it by typing:
sudo update-rc.d isc-dhcp-server remove
then set up the new wlan0-restart script with
sudo update-rc.d wlan0-restart defaults
before setting up the isc-dhcp server again with
sudo update-rc.d isc-dhcp-server defaults

If you follow the quick install method using the tvrouter.zip file, you can setup the wlan0-restart script at point 8a, BEFORE installing the isc-dhcp-server, then you will not have to remove it with update-rc.d and reset it again, but merely use update-rc.d to setup the wlan0-reset script.

Hopefully this should enable the project to work with the latest Raspian distribution again as it is currently doing on my Pi2. You will see some error messages on the screen when the script is invoked, but you can ignore these as it does work.! When the boot process has completed you should see two ip addresses listed on the screen. The first will be the ethernet address (192.168.2.1) and the second the wlan0 address (192.168.1.98)
All being well, you should be able to log on and ping your mail wireless router (probably on 192.168.1.1) and your tv (or laptop) connected to the ethernet port which will probably have been served the ip address 192.168.2.10. Remember if you use a different address for the wlan0 port you will have to rebuild the iptables as discussed in the original article.

Two final points. First, the quick install does NOT point out that you SHOULD alter the interfaces file once you have installed it to reflect your own ssid and password

Secondly, many people have asked me if it is possible to use the project with dlna devices. to access media content. Unfortunately it was not designed with this in mind, and dlna will not easily work across a router (which is what this project is!) as it is designed for use on a single local network, relying on broadcast signals. I have read many articles looking at this problem but have not seen a satisfactory solution to this yet, so don’t ask me! Of course if you know how it can be done, I and many others would love to know.

 

15 thoughts on “Amendements to TVRouter article of July 2013

  1. I have an entry in the /etc/network/interfaces:

    post-up /bin/restart_wifi

    The restart_wifi script looks like this:

    sudo ifdown wlan0
    sudo ifup wlan0

    Yet, I often still have to execute the script manually after reboot to get wifi working.

    I can’t recall where I saw the post to invoke the script vai the post-up command in the /etc/network/interfaces file. Would you expect it to behave differently if I use something like the /etc/init.d/wlan0-restart you suggest?

    I also vaguely recall reading something about an rpi 2 issue needing something like a delay in a /boot/config.txt file. That was in the context of setting up a hotspot, IIRC. But, I’m thinking maybe there’s some sort of timing issue. When I restart wifi manually after reboot, it’s 100% reliable. Using the post-up command, it boots with wifi working only about 50% of the time.

    Thanks,

    Dave Thoams

  2. I have been using this for a while now, however i use it to connect to a near by “hotspot” and then rout the connection to a cheap router via ethernet, and then have all my devices conected to the new network i created with the router i have a media/torrent server and use it to stream throughout my house. By using this none of my devices show on the original network other then the raspberry pi.

    Great work i love this little guy free internet without being caught

  3. I cannot get this working :( – the scripts appear to function etc… but after i sort out the routes, the pi can’t see the internet? but I can ssh into the pi from my mac… I’m a network novice so routing is over my head…

  4. Hi I have come from the original post which worked fine for me on the latest distribution. One question: how could I use this to access a printer which is on my main network from my subnetwork

  5. Hi, I know this is the old post but your new post doesn’t have reply section.

    Anyway, I am trying to follow your method but it is not working. I tried to connect to xfinitywifi public wifi hotspot and share through Linksys router (Internet Slot) but it is not working. Do you have any suggestion for me?

    The IP that I got from xfinitywifi is 172.20.20.20. I tried to change from your setting but end up I cannot connect to xfinitywifi and cannot share internet to my router.

      • Hi Kamchai
        Sorry you are having difficulty. If you use different IP addresses then this will mean several changes, especially in the ip-tables code and you will have to build your own files here using the scripts described in the first article. I’m not quite sure what you mean by every device on your xinfinitywifi has the same ip address. I don’t see how this is possible, as you cannot differentiate between them. You may be interested to know that I am currently evaluating a different approach to this project which keeps both the wifi connected and local connected devices on the same network, using Proxy ARP. I have this working on a Raspberry Pi 3, but need to experiment a bit further with it. It is based on an article at https://wiki.debian.org/BridgeNetworkConnectionsProxyArp

      • This is from my Mac

        Wi-Fi is connected to xfinitywifi and has the IP address 172.20.20.20.

        This is from my Pi

        pi@MyPy:~ $ hostname -I
        172.20.20.20

        So Im not sure should I use this IP in this case.

  6. I am new to Linux networking and I am trying to set up my CCTV system. My problem is described as follows – A pocket sized, mobile 3G router without any ethernet interfaces attaches my Pi to the internet on wlan0. I use reverse tunneling, actually a proxy service from remot3.it, to connect to services like apache2, ssh etc….on specific ports. My cheap chinese DVR only has an ethernet interface, so I use an old wifi router to connect both, the pi and the DVR, to a local network. Using iptables, I can forward incoming calls on port 8888 to the DVR ip. Now, when I attach my android tablet to the 3G router hotspot, I can establish a connection with the DVR on port 8888 and see life video with a client application (ASEE+). However, I get network errors when doing this over the proxy service and I am still not sure why. Actually, I could buy a proper 3/4G wifi router with ethernet ports but that would cost me over 100 Euros. Instead, what I want to do first is to get rid of the wifi router and attach the DVR directly to the Pi on eth0. So I need a kind of Pi hotspot.

    What is the difference between your setup and setting up an access point using hostapd ?

Leave a comment