JolHarg Blog
  • JolHarg
  • » JolHarg Blog » How to use SSH for an Internet Connection Sharing Proxy
    All Posts
    2025

    March

    I use OpenNIC for DNS, it's cool, independent and custom


    Behind the Times: Sites still without IPv6 in 2025


    2024

    December

    Updated Websites and Blogs!


    Everything I maintain now built with GHC 9.10


    November

    Updated Websites


    2022

    December

    Raspberry Pi Pico (W) on NixOS


    October

    This blog now built with GHC 9.4


    September

    Google tip: Set ?authuser=[email]


    Welcome to my new tech blog


    Error messages have still not changed


    March

    This blog now built with GHC 9.2


    2021

    November

    Sorry, something somewhere went wrong!


    October

    Facebook being down killed AdGuard


    March

    Ephemeral system with NixOS


    2018

    August

    Spotify (and Netflix) on Chromium, with help from Steam, without root!


    Quick phone tip: make your phone seem faster by disabling animations


    July

    Issuing modem commands to an unrooted Android device


    Retro dial-up network fun


    2016

    October

    Project Chaplin 0.3.2 point release


    September

    Project Chaplin 0.3.1 Released


    2015

    April

    Project Chaplin Beta 2 Released


    Project Chaplin Video Sharing Beta Released


    March

    BSD for Linux Users: An Introduction


    2012

    May

    The Rules of Website Advertising


    2011

    October

    New Project: View and Share Media Online


    March

    Play.com compromised, names and emails taken


    2010

    November

    How to use SSH for an Internet Connection Sharing Proxy


    October

    Rules of Mobile Platform Development


    September

    Bibud Alpha 5.1 released


    August

    Bibud Social Web Desktop Alpha5 Released


    February

    Xenon Web Desktop Alpha2 Released


    January

    Linux's Hardware Support


    2009

    December

    Xenon Alpha released!


    November

    Sync iPhone/iPod Touch 3G in Ubuntu


    Best Security Practices For Your Personal Computer


    October

    Xenon Project looking for helpers!


    September

    Linux Myths Debunked


    Linux is not ready for the mainstream


    August

    How to Conquer the Desktop


    July

    What Free Software needs


    2008

    October

    Cloud OS


    September

    Standards


    Sun is dead?


    All Posts
    2025

    March

    I use OpenNIC for DNS, it's cool, independent and custom


    Behind the Times: Sites still without IPv6 in 2025


    2024

    December

    Updated Websites and Blogs!


    Everything I maintain now built with GHC 9.10


    November

    Updated Websites


    2022

    December

    Raspberry Pi Pico (W) on NixOS


    October

    This blog now built with GHC 9.4


    September

    Google tip: Set ?authuser=[email]


    Welcome to my new tech blog


    Error messages have still not changed


    March

    This blog now built with GHC 9.2


    2021

    November

    Sorry, something somewhere went wrong!


    October

    Facebook being down killed AdGuard


    March

    Ephemeral system with NixOS


    2018

    August

    Spotify (and Netflix) on Chromium, with help from Steam, without root!


    Quick phone tip: make your phone seem faster by disabling animations


    July

    Issuing modem commands to an unrooted Android device


    Retro dial-up network fun


    2016

    October

    Project Chaplin 0.3.2 point release


    September

    Project Chaplin 0.3.1 Released


    2015

    April

    Project Chaplin Beta 2 Released


    Project Chaplin Video Sharing Beta Released


    March

    BSD for Linux Users: An Introduction


    2012

    May

    The Rules of Website Advertising


    2011

    October

    New Project: View and Share Media Online


    March

    Play.com compromised, names and emails taken


    2010

    November

    How to use SSH for an Internet Connection Sharing Proxy


    October

    Rules of Mobile Platform Development


    September

    Bibud Alpha 5.1 released


    August

    Bibud Social Web Desktop Alpha5 Released


    February

    Xenon Web Desktop Alpha2 Released


    January

    Linux's Hardware Support


    2009

    December

    Xenon Alpha released!


    November

    Sync iPhone/iPod Touch 3G in Ubuntu


    Best Security Practices For Your Personal Computer


    October

    Xenon Project looking for helpers!


    September

    Linux Myths Debunked


    Linux is not ready for the mainstream


    August

    How to Conquer the Desktop


    July

    What Free Software needs


    2008

    October

    Cloud OS


    September

    Standards


    Sun is dead?


    How to use SSH for an Internet Connection Sharing Proxy

    Permalink | Author: Dan Dart | Published: 2010-11-13 13:10:00 UTC | Tags: connection internet internet connection sharing linux proxy sharing ssh tunnel


    I haven't made a blog in a long while, so I'd thought I'd share this, which I recently discovered how to do.

    If you find the idea of proxies a bit restrictive. because after all, they have to be set up in the applications in question, and may not work for some applications, help is here. And all you need is an SSH server you can connect to. Sadly, this method requires root, but it's worth having for the system-wide Internet connection you'll get from it.


    Authenticating as root

    First, make sure you're root on the client machine (sudo -s or su -, depending on your distro), and that you can ssh as root to your target server. This is of course causes security implications, so it may be a good idea to generate a key pair for root-to-root access and block off passworded access for root, so that no one can bruteforce your root password.

    Generate the key pair as root on the client:

    client:~# ssh-keygen

    And copy the key to the server

    client:~# ssh-copy-id [server]

    Test the root login. It should not prompt you for password authentication (unless you've set one in ssh-keygen). Now, to block off password logins, edit /etc/ssh/sshd_config (or /etc/sshd/sshd_config) on the server and make sure this line is present:

    PermitRootLogin without-password

    Hooray! We're now somewhat more secure!


    Creating the tunnel

    Now to start a tunnel. The -w switch on ssh will do what we need, and create a tunnel network interface on both computers. The first number is the number of the interface on the client, and the second is for the server. For example, 0:! will create tun0 on the client connected to tun1 on the server. You may specify auto for the next available one. Let's create tunnels called tun0 to make it simpler.

    client:~# ssh -w0:0 [server]

    Now, see if your tunnels were set up correctly.

    server:~# ifconfig -a tun0

    You should see a tun0 interface. This is a layer 3 tunneled virtual interface (point-to-point).

    Set up an IP on both sides so each computer can talk to each other.

    server:~# ifconfig tun0 10.0.0.1 pointopoint 10.0.0.2
    client:~# ifconfig tun0 10.0.0.2 pointopoint 10.0.0.1`

    Try pinging each side to see if you have a connection.

    Once each host can talk to the other, we can set up the routing.

    Setting up the routing

    Server setup

    Ensure that the tun0 interface is not restricted:

    server:~# iptables -A INPUT -i tun0 -j ACCEPT
    server:~# iptables -A OUTPUT -o tun0 -j ACCEPT
    server:~# iptables -A FORWARD -i tun0 -j ACCEPT

    Allow packets in from the external interface to be processed by the tunnel:

    server:~# iptables -A INPUT -i eth0 -d 10.0.0.2 -j ACCEPT

    Allow forwarded packets to be routed to their destination:

    server:~# iptables -A FORWARD -i eth0 -o tun0 -j ACCEPT`

    Set up tun0 for NAT:

    server:~# iptables -A POSTROUTING -o tun0 -t nat -j MASQUERADE

    Enable IP forwarding in the kernel:

    server:~# echo 1 > /proc/sys/net/ipv4/ip_forward`

    Client setup

    Allow packets to be processed from the tun0 interface:

    client:~# iptables -A INPUT -i tun0 -j ACCEPT
    client:~# iptables -A OUTPUT -o tun0 -j ACCEPT
    client:~# iptables -A FORWARD -i tun0 -j ACCEPT`

    Setting up the gateways

    Find the existing default gateway:

    client:~# route | grep ^default

    Add a backbone to stop the server not being found once we switch gateways:

    client:~# route add [server IP] gw [existing default gateway]`

    Add the new default gateway:

    client:~# route add default gw 10.0.0.1

    Remove the existing default gateway (Be very careful!):

    client:~# route del default gw [existing default gateway]`

    Testing the tunnel

    Try going to whatismyip.com in your browser. It should show you the IP of your server. If you're curious, you can also check the default route to somewhere like Google by using the traceroute utility.

    You're done!

    Troubleshooting

    I can't see a tun0 interface!

    Make sure you're root on both sides. (It sounds obvious - I've thumped my head on my desk so much because of this!)

    Start ssh with the -v switch to show more verbosity. If you see a message a bit like this:

    debug1: Remote: Failed to open the tunnel device.
    channel 0: open failed: administratively prohibited: open failed

    it could mean that someone else is trying to create a tunnel with the same interface name on the server.

    If you see something a little like this:

    debug1: sys_tun_open: failed to configure tunnel (mode 1): Device or resource busy

    it might mean that you already have a tunnel with that interface name open. Check ifconfig -a.

    I get the message "ping: sendmsg: Operation not permitted" when testing the tunnel connection!

    You didn't allow traffic to flow between the tunnel and local network device. Try turning the client firewall off.

    The connection is slow!

    There will be significant overhead as all the traffic is encapsulated into SSH and encrypted. You will also see latencies go up as traffic needs to travel from your client to your server and back additionally.



    Comments

    prolix (URL) said on 2011-10-14T06:59:13.224Z:

    Excellent read. I like your style...have a good one!/Nice blog! Keep it up!



    Post a comment:



    Tags
    • 2
      • 2025
    • 6
      • 64 bit
    • 9
      • 98
      • 9.4
      • 9.2
      • 9.10
    • a
      • azure
      • avast
      • authuser
      • audio
      • argument
      • apps
      • apple
      • appcache
      • app
      • api
      • anti
      • annoying
      • animation
      • android
      • amazon
      • alpha
      • ajax
      • adwords
      • advertising
      • adsense
      • ads
      • adguard
      • address
      • access
    • b
      • built
      • bsd. competition
      • bsd
      • broadcasting
      • blogs
      • blog
      • bilibili
      • bibud
      • bgp
      • behind
      • baidu
    • c
      • custom
      • css
      • creativecommons
      • cracker
      • core
      • copy
      • cool
      • content
      • connection
      • computer
      • compromise
      • company
      • command line
      • com
      • cnn
      • cloud
      • client
      • chromium
      • chrome
      • chatgpt
      • chaplin
      • changed
      • change
      • cddl
      • cc
      • canva
      • cabal
    • d
      • dzen
      • duckduckgo
      • drm
      • drawing
      • dragonflybsd
      • dragonfly
      • dns
      • dialup
      • dial-up
      • dfp
      • device
      • desktop
      • design
      • delete
      • debunked
      • debian
      • dart
      • dailymotion
    • e
      • everything
      • error
      • ephemeral
      • emulation
      • emulate
      • email
      • emai
      • eggs
      • ebay
      • easter
    • f
      • friends
      • freebsd
      • free software
      • free
      • format
      • floss
      • flash
      • firewall
      • files
      • feed
      • fast
      • fandom
      • facebook
    • g
      • gui
      • gsm
      • gpl
      • google
      • gnu
      • gnome
      • globo
      • github
      • git
      • ghc
    • h
      • html5
      • html
      • htc
      • hiatus
      • hayes
      • haskell
      • hardware
      • hacker
    • i
      • itunes
      • isp
      • ipv6
      • ipod
      • internet connection sharing
      • internet
      • intel
      • independent
      • import
      • illusion
      • i7
    • j
      • jim
      • javascript
    • k
      • kernel
      • kde
    • l
      • live
      • linux
      • linkedin
      • licence
      • library
      • libraries
      • l
    • m
      • myths
      • mysql
      • my
      • motorola
      • modem
      • mobile
      • mit
      • minicom
      • microsoft
      • meta
      • messages
      • media
      • market
      • maintain
      • mail.ru
      • m2msupport
    • n
      • not
      • nostalgia
      • nixos
      • new
      • networking
      • network
      • netflix
      • netbsd
      • naver
      • nat
      • naming
    • o
      • oss
      • os
      • operating system
      • opensuse
      • opennic
      • openbsd
      • open source
      • open
    • p
      • public
      • proxy
      • protocol
      • protected
      • projectchaplin
      • project
      • port
      • play
      • pinterest
      • pico
      • pi
      • php
      • phone
      • pcbsd
      • password
      • packages
    • q
      • quora
    • r
      • rules
      • routing
      • rootkit
      • root
      • relevant
      • release
      • reddit
      • recording
      • raspberry
      • rakuten
    • s
      • system
      • support
      • sun
      • still
      • steam
      • standardisation
      • standard
      • ssh
      • sql
      • spotify
      • sorry
      • somewhere
      • something
      • solaris
      • software
      • social
      • sites
      • sharing
      • share
      • settings
      • server
      • serial
      • seo
      • security
      • search
      • screen
      • sco
      • scale
      • samsung
    • t
      • twitch
      • tunnel
      • trojan
      • to
      • tip
      • times
      • tiktok
      • tetlegram
      • temu
      • tech
    • u
      • usb
      • updates
      • updated
      • update
      • unix
      • ubuntu
    • v
      • vk
      • visual
      • vista
      • virus
      • vimeo
      • videos
      • video
    • w
      • wrong
      • worm
      • without
      • with
      • windows
      • wikipedia
      • widevine
      • whoops
      • went
      • welcome
      • websites
      • website
      • webos
      • webm
      • web
      • weather.com
      • war
      • w
    • x
      • xp
      • xhtml
      • xenon
      • x
    • y
      • youtube
      • yahoo
    • z
      • zoom
      • zfs
      • zemlin
    Tags
    • 2
      • 2025
    • 6
      • 64 bit
    • 9
      • 98
      • 9.4
      • 9.2
      • 9.10
    • a
      • azure
      • avast
      • authuser
      • audio
      • argument
      • apps
      • apple
      • appcache
      • app
      • api
      • anti
      • annoying
      • animation
      • android
      • amazon
      • alpha
      • ajax
      • adwords
      • advertising
      • adsense
      • ads
      • adguard
      • address
      • access
    • b
      • built
      • bsd. competition
      • bsd
      • broadcasting
      • blogs
      • blog
      • bilibili
      • bibud
      • bgp
      • behind
      • baidu
    • c
      • custom
      • css
      • creativecommons
      • cracker
      • core
      • copy
      • cool
      • content
      • connection
      • computer
      • compromise
      • company
      • command line
      • com
      • cnn
      • cloud
      • client
      • chromium
      • chrome
      • chatgpt
      • chaplin
      • changed
      • change
      • cddl
      • cc
      • canva
      • cabal
    • d
      • dzen
      • duckduckgo
      • drm
      • drawing
      • dragonflybsd
      • dragonfly
      • dns
      • dialup
      • dial-up
      • dfp
      • device
      • desktop
      • design
      • delete
      • debunked
      • debian
      • dart
      • dailymotion
    • e
      • everything
      • error
      • ephemeral
      • emulation
      • emulate
      • email
      • emai
      • eggs
      • ebay
      • easter
    • f
      • friends
      • freebsd
      • free software
      • free
      • format
      • floss
      • flash
      • firewall
      • files
      • feed
      • fast
      • fandom
      • facebook
    • g
      • gui
      • gsm
      • gpl
      • google
      • gnu
      • gnome
      • globo
      • github
      • git
      • ghc
    • h
      • html5
      • html
      • htc
      • hiatus
      • hayes
      • haskell
      • hardware
      • hacker
    • i
      • itunes
      • isp
      • ipv6
      • ipod
      • internet connection sharing
      • internet
      • intel
      • independent
      • import
      • illusion
      • i7
    • j
      • jim
      • javascript
    • k
      • kernel
      • kde
    • l
      • live
      • linux
      • linkedin
      • licence
      • library
      • libraries
      • l
    • m
      • myths
      • mysql
      • my
      • motorola
      • modem
      • mobile
      • mit
      • minicom
      • microsoft
      • meta
      • messages
      • media
      • market
      • maintain
      • mail.ru
      • m2msupport
    • n
      • not
      • nostalgia
      • nixos
      • new
      • networking
      • network
      • netflix
      • netbsd
      • naver
      • nat
      • naming
    • o
      • oss
      • os
      • operating system
      • opensuse
      • opennic
      • openbsd
      • open source
      • open
    • p
      • public
      • proxy
      • protocol
      • protected
      • projectchaplin
      • project
      • port
      • play
      • pinterest
      • pico
      • pi
      • php
      • phone
      • pcbsd
      • password
      • packages
    • q
      • quora
    • r
      • rules
      • routing
      • rootkit
      • root
      • relevant
      • release
      • reddit
      • recording
      • raspberry
      • rakuten
    • s
      • system
      • support
      • sun
      • still
      • steam
      • standardisation
      • standard
      • ssh
      • sql
      • spotify
      • sorry
      • somewhere
      • something
      • solaris
      • software
      • social
      • sites
      • sharing
      • share
      • settings
      • server
      • serial
      • seo
      • security
      • search
      • screen
      • sco
      • scale
      • samsung
    • t
      • twitch
      • tunnel
      • trojan
      • to
      • tip
      • times
      • tiktok
      • tetlegram
      • temu
      • tech
    • u
      • usb
      • updates
      • updated
      • update
      • unix
      • ubuntu
    • v
      • vk
      • visual
      • vista
      • virus
      • vimeo
      • videos
      • video
    • w
      • wrong
      • worm
      • without
      • with
      • windows
      • wikipedia
      • widevine
      • whoops
      • went
      • welcome
      • websites
      • website
      • webos
      • webm
      • web
      • weather.com
      • war
      • w
    • x
      • xp
      • xhtml
      • xenon
      • x
    • y
      • youtube
      • yahoo
    • z
      • zoom
      • zfs
      • zemlin
  • Atom Feed