Redirect IP Address to localhost

. 1 min read

I had some of my code (terrible as usual) pointing to an IP Address. I had downloaded my code to a local machine and wanted to use the same code to function of my local server!

I had the following options:

  • Update the ipaddresses in my code to the localhost
  • Cleanup the code to use a config file

Both of these are going to take some time and effort.

To overcome the problem, I decided to use a small hack!

I decided to point the address on my localsystem back to my localhost using the following command:

sudo iptables -t nat -A OUTPUT -p all -d 104.131.61.242 -j DNAT --to-destination 127.0.0.1

That's it! My code works on my local machine like magic using the same remote ipaddress code

Credit: hosts - How to change IP address to point to localhost? - Super User

For doing the same on Mac OSX:

To enable:

sudo ifconfig lo0 alias 104.131.61.242

To disable:

sudo ifconfig lo0 -alias 104.131.61.242

Further, check links here: https://serverfault.com/questions/102416/iptables-equivalent-for-mac-os-x/673551#673551

sudo ifconfig lo0 104.131.61.242 alias
echo "rdr pass on lo0 inet proto tcp from any to 104.131.61.242 port 27017 -> 127.0.0.1 port 27017" | sudo pfctl -ef -

Tags

AWS Analytics Antifragile Apache Spark Apple Apps Arbitrage Automation Awesome BBMP Bangalore Black Swan Bonds Boonex Bootstrap Brokerage Charges CFPB CMS CSS Calypso Camelot Capital Markets Charts Chirp Choropleth Chrome Code Igniter Collections Containerization Converters Cycling DalalBeat Data Analytics Data Journalism Data Mining Data Munging Data Privacy Data Science Databases Debt Design Design Stock DesignStock Diet Django Docker Document Processing Dropbox Electron Electronics Entertainment Entrepreneurship Exercise FFMPEG Facebook Finance Fire TV Stick Fitness Forerunner From-The-News Fun Futures Gaana Garmin General Geocoding Getting Started Ghost Google APIs GraphicsMagick HHVM HTTPS Hackathon Hacks Hardware Health House Keeping Housing IBM BlueMix IBrokers IPinfo Ideas Image Conversion Image Processing Infographics Interactive Brokers Internet Investing IoT Legal Lets Encrypt Mac Machine Learning Mailbox app Mapbox Markdown Marketing Meteor Mockups MongoDB Mortgages Movies Music MyPad MySQL Nativefier Nature Netflix Newsletters Nginx Node.js Notes OCR OSX Open Source OpenCPU Options PDF PHP Pebble Peloton Personal Photography Picture Platforms Plex Portable Apps Productivity Property Tax PyroCMS Quantitative Finance R-Project Random Raspberry Pi Research Resources Reticulate Robot S3 SQLite STT Scraping Security Server Shell Shiny Side Project Sikuli Speech Recognition Spider Pro Spinning Spotify Startup Resources Startups Strategy Sublime Text System Monitoring Tax Terminal Tips To Do Tools Torrent Trading Trends Troubleshooting USElection2016 Ubuntu Unix Valuations Video Conversion Visualization Wagtail Wearables Weekend Fun WhatsApp Wordpress anaconda annie bash catalina cv2 daily coding dailycoding data.table debugging devtools downloader e-Signatures ggplot git go google maps hat-tip iOS iPad iPhone iTunes javascript jupyter logging macos numpy opencv optionality plotly python rstats videos youtube