ABN 25 173 915 011 markomedia - web development

markomedia - web development

  • Home
  • Contact
  • Blog

November 4, 2009

SSH Tunneling – Add secondary address to your loopback interface HOWTO

  • markomedia
    • OS X
      • SSH Tunneling – Add secondary address to your loopback interface HOWTO
Share |
  • Author
    Marko Tomic
    Category
    OS X
    Tags
    OS X, SSH
    Comments
    0

    I’m writing this one for my own reference because almost everything I do for work, is done through SSH port forwarding. If you’re not familiar with SSH port forwarding, you’ll have to read up on it elsewhere. And the reason why we use SSH port forwarding is because it is secure and powerful.

    I generally set up my port forwards to run on my local computer on an arbitrary port and configure SSH to create a proxy connection to the normal port on a remote computer. Then I configure my application to connect to my local computer on the chosen arbitrary port.

    For example, I would add the following in my hosts file:

    sudo nano /etc/hosts
    127.0.0.1 local1A.fwd
    127.0.0.1 local1B.fwd
    127.0.0.1 local1C.fwd

    let’s say I want to forward my local requests on ports 6800, 6801, 6802 to remote servers on ports 3012, 3013, 3014. Start by modifying your ssh config:
    nano .ssh/config
    add the following:

    host remote1A
    hostname 111.111.111.111 #remote IP address goes here
    user my_username #server username goes here
    localforward local1A.fwd:6800 111.111.111.111:3012
     
    host remote1B
    hostname 111.111.111.111 #remote IP address goes here
    user my_username #server username goes here
    localforward local1B.fwd:6801 111.111.111.111:3013
     
    host remote1C
    hostname 111.111.111.111 #remote IP address goes here
    user my_username #server username goes here
    localforward local1C.fwd:6802 111.111.111.111:3014

    You should now be able to ssh to remote machines:

    ssh remote1A

    and similarly for 1B and 1C.

    Now, lets say you want to create another 3 local hosts and simultaneously port forward to another 3 remote machines via exact same port numbers. This is where you’ll run into problems, because you can only use one local port at a time on 127.0.0.1. The workaround it is to create secondary addresses to your loopback interface 127.0.0.2, 127.0.0.3 and so on. The command to add the secondary IP address is:

    sudo ifconfig lo0 alias 127.0.0.2/32

    Now you can add new set of hosts:

    127.0.0.2 local2A.fwd
    127.0.0.2 local2B.fwd
    127.0.0.2 local2C.fwd

    And use the same set of port numbers to tunnel through another set of remote servers:

    host remote2A
    hostname 222.222.222.222 #remote IP address goes here
    user my_username #server username goes here
    localforward local1A.fwd:6800 222.222.222.222:3012
     
    host remote2B
    hostname 222.222.222.222 #remote IP address goes here
    user my_username #server username goes here
    localforward local1B.fwd:6801 222.222.222.222:3013
     
    host remote2C
    hostname 222.222.222.222 #remote IP address goes here
    user my_username #server username goes here
    localforward local1C.fwd:6802 222.222.222.222:3014

    Marko

  • Previous post
  • Next post
Top

Related posts

  • opendiff and FileMerge on OS X
  • Bandwidth throttling on OS X
  • bash script useful tips
  • apr_sockaddr_info_get() failed for mydomain.com
  • AES-128 padded encryption/decryption with Railo, Java and AS3

Share this post

Author Marko Tomic

Gravatar

Leave a comment

No comments yet.

Search

QR Code

Recent Posts

  • FileMerge

    opendiff and FileMerge on OS X

  • Bandwidth throttling on OS X

  • bash script useful tips

Popular

  • Verizon Activates 2.2 Million iPhones in First Quarter

  • Amazon Server Trouble, Obama’s Facebook Visit.

  • Best Practices for Android Developers

Comments

  • Marko Tomic on Zen Cart to VirtueMart csv export
  • snake on Zen Cart to VirtueMart csv export
  • Marko Tomic on Flash to Flex ComponentEvent coercion error solved
  • Thomas on Flash to Flex ComponentEvent coercion error solved
  • Increase PHP file upload limit – markomedia – Web Development | Files U, Apache on Increase PHP file upload limit

Tags

  • Apache6
  • AS36
  • bash2
  • ColdFusion2
  • command1
  • difftool1
  • DVD1
  • filemerge1
  • Flash3
  • Flex6
  • general2
  • Handbreak1
  • HOWTO8
  • iPhone1
  • iTunes1
  • Jaber1
  • java5
  • Linux3
  • MySQL3
  • networking1
  • opendiff1
  • OS X8
  • PHP3
  • Railo4
  • Red52
  • S31
  • shell3
  • SQL1
  • SSH2
  • SSL1
  • SVN1
  • tar1
  • Terminal3
  • Tigase1
  • Tomcat2
  • Ubuntu2
  • utilities1
  • VirtueMart1
  • XMPP1
  • ZenCart2
  • zip1

Contact us

  • Call us

Archive

  • January 2012
  • December 2011
  • November 2011
  • October 2011
  • September 2011
  • August 2011
  • July 2011
  • May 2011
  • December 2010
  • October 2010
  • September 2010
  • August 2010
  • July 2010
  • June 2010
  • May 2010
  • April 2010
  • February 2010
  • January 2010
  • December 2009
  • November 2009
  • October 2009

Navigation

  • Home
  • Contact
  • Blog

Archives

  • January 2012
  • December 2011
  • November 2011
  • October 2011
  • September 2011
  • August 2011
  • July 2011
  • May 2011
  • December 2010
  • October 2010
  • September 2010
  • August 2010
  • July 2010
  • June 2010
  • May 2010
  • April 2010
  • February 2010
  • January 2010
  • December 2009
  • November 2009
  • October 2009

From the blog

  • opendiff and FileMerge on OS X

  • Bandwidth throttling on OS X

  • bash script useful tips

  • apr_sockaddr_info_get() failed for mydomain.com

  • AES-128 padded encryption/decryption with Railo, Java and AS3

About us

Marko Tomic - Web professional and an Adobe Certified Expert with over 10 years of commercial experience using variety of technologies.

Connect

Facebook icon Twitter icon Email icon RSS icon