如何在.pac文件中的myIpAddress()上避免127.0.0.1

如何在.pac文件中的myIpAddress()上避免127.0.0.1

问题描述:

任何想法如何避免myIpAddress()总是返回127.0.0.1,而不是实际的主机IP地址?如何在.pac文件中的myIpAddress()上避免127.0.0.1

环境是Ubuntu 11.04与Firefox 4.0.1。

Wikipedia上删除/ etc/hosts文件中的条目的标准答案没有帮助。

终于奏效了,是用IP地址正确更新/ etc/hosts中的条目。

在Ubuntu中,/etc/network/if-up.d目录中的可执行文件在网络管理器配置网络接口后执行。

这个脚本会更新相应的IP地址:

#!/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