Created
February 8, 2015 15:36
-
-
Save ravage/9360e129f4c90ce90c47 to your computer and use it in GitHub Desktop.
Replace 127.0.1.1 in /etc/hosts entry with real address
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# find the interface with the default route | |
interface=$(ip route | grep default | awk '{ print $5; exit }') | |
# get ip address from discovered interface | |
address=$(ifconfig $interface | egrep '([0-9]{1,3}\.){3}[0-9]{1,3}' -o | head -1) | |
# prepare address for sed | |
escaped_address=$(echo $address | sed -E 's/\./\\\./g') | |
# what to replace | |
search_address=127\.0\.1\.1 | |
# execute replace saving the file with .bak extension | |
sed -i.bak "s/$search_address/$escaped_address/g" /etc/hosts |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment