maxgallo
maxgallo

Reputation: 478

Add route from single ip to localhost. OSX Mavericks

on my MacbookPro 15'' Retina, with OSX 10.9.4, I want to be able to: route all single ip traffic to localhost.

My Goal is this:

I type http://192.168.1.54/test.html in the browser and I get what I normally get from http://localhost/test.html

This is what I tried (en4 is the one I get internet connection from):

______$ sudo route add 192.168.1.54 localhost -ifp en4

checking the list

______$ sudo route add 192.168.1.54 localhost -ifp en4
add host 192.168.1.54: gateway localhost
______$ netstat -rn
Routing tables

Internet:
Destination        Gateway            Flags        Refs      Use   Netif Expire
default            192.168.1.1        UGSc           42        4     en4
127                127.0.0.1          UCS             0        3     lo0
127.0.0.1          127.0.0.1          UH             50    15380     lo0
...
192.168.1.54       127.0.0.1          UGHS            0        0     en4
...

But the ping of 192.168.1.54 isn't working

I tried also the loopback interface with

______$ sudo route add 192.168.1.54 localhost -ifp lo0

getting the same result: nothing.

I'm kind of a newbie in this stuff, so any help will be great

Upvotes: 4

Views: 4782

Answers (2)

Jonyx4
Jonyx4

Reputation: 156

Fire up your Terminal and type the following:

sudo ifconfig lo0 alias 192.168.66.66

After entering your password, that will redirect requests for 192.168.66.66 to the localhost/loopback adapter.

And if you need to remove this redirect, try

sudo ifconfig lo0 -alias 192.168.66.66

Source: http://www.vincecutting.co.uk/web-development/redirect-ip-address-back-to-localhost-on-mac-osx/

Upvotes: 7

Gene Mat
Gene Mat

Reputation: 66

You'll need to create a mac virtual interface pointing to 192.168.1.54. Otherwise there is no one to reach at 192.168.1.54 and hence why your ping is failing.

In linux it's pretty straight forward to create additional virtual interfaces.

On my mac osx machine I was able to go into Systems Preferences --> Network then hit the + sign to add an additional interfaces.

I picked Ethernet as my interface type and assigned the address of 192.168.1.54, 255.255.255.0 subnet mask and 192.168.1.1 as the default router.

Now both my primary 192.168.1.10 and my virtual 192.168.1.54 interfaces are up and pingable.

en0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
        options=10b<RXCSUM,TXCSUM,VLAN_HWTAGGING,AV>
        ether 0c:4d:e9:9a:1c:a3 
        inet6 fe80::e4d:e9ff:e936:1ca3%en0 prefixlen 64 scopeid 0x4 
        inet 192.168.1.10 netmask 0xffffff00 broadcast 192.168.1.255
        inet 192.168.1.54 netmask 0xffffff00 broadcast 192.168.1.255
        nd6 options=1<PERFORMNUD>
        media: autoselect (100baseTX <full-duplex>)
        status: active


My-Book-Pro:~ root# ping 192.168.1.10
PING 192.168.1.10 (192.168.1.10): 56 data bytes
64 bytes from 192.168.1.10: icmp_seq=0 ttl=64 time=0.095 ms
64 bytes from 192.168.1.10: icmp_seq=1 ttl=64 time=0.101 ms

My-MacBook-Pro:~ root# ping 192.168.1.54
PING 192.168.1.54 (192.168.1.54): 56 data bytes
64 bytes from 192.168.1.54: icmp_seq=0 ttl=64 time=0.085 ms
64 bytes from 192.168.1.54: icmp_seq=1 ttl=64 time=0.091 ms

Upvotes: 0

Related Questions