开发者

How to avoid 127.0.0.1 on myIpAddress() in .pac files

Any idea how to avoid myIpAddress() always returning 127.0.0.1, instead of actual the host IP address?

Environment is Ubuntu 11.04 with Firef开发者_JAVA技巧ox 4.0.1.

The standard answer on Wikipedia of removing entries from the /etc/hosts file didn't help.


What has finally worked, was to update the entry in /etc/hosts correctly with the IP address.

In Ubuntu, executable files in the /etc/network/if-up.d directory are being executed after the network manager configures a network interface.

This script does update the ip address accordingly:

#!/bin/sh

set -e

if [ "$IFACE" = lo ]; then
    exit 0
fi

myHostName=T410

# Remove current line with hostname at the end of line
sed -i '/'$myHostName'$/ d' /etc/hosts

# Add new entry to hosts file
ipaddr=$(ifconfig  | grep 'inet addr:'| grep -v '127.0.0.1' | cut -d: -f2 | awk '{ print $1}')
echo "$ipaddr $myHostName" >>/etc/hosts
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜