echo `ifconfig $(netstat -nr | grep -e default -e "^0\.0\.0\.0" | head -1 | awk '{print $NF}') | grep -e "inet " | sed -e 's/.*inet //' -e 's/ .*//' -e 's/.*\://'`
- Press the Windows key.
- Type Notepad in the search field.
- In the search results, right-click Notepad and select Run as administrator.
- From Notepad, open the following file: c:\Windows\System32\Drivers\etc\hosts
- Make the necessary changes to the file.
- Click File > Save to save your changes.
- Click Start > All Programs > Accessories.
- Right-click Notepad and select Run as administrator.
- Click Continue on the Windows needs your permission UAC window.
- When Notepad opens, click File > Open.
- In the File name field, type C:\Windows\System32\Drivers\etc\hosts.
- Click Open.
- Make the necessary changes to the file.
- Click File > Save to save your changes.
- Click Start > All Programs > Accessories > Notepad.
- Click File > Open.
- In the File name field, type C:\Windows\System32\Drivers\etc\hosts.
- Click Open.
- Make the necessary changes to the file.
- Click File > Save to save your changes.
Another way to edit the hosts file directly is to use I/O redirection from cmd. It will not restrict you from editing the hosts file like the gui.
Launch cmd with elevated privileges (as administrator)
cd / navigate to the etc folder then issue your host entries using the following syntax
echo host_entry >> target_file
e.g. echo 127.0.0.1 localhost >> hosts
This will append your host entries at the end of the hosts file. Make sure you use the double greater than sign >> because using a single one > results in ovewriting whatever is already in the hosts file.