问题描述
||
任何想法如何避免myIpAddress()总是返回127.0.0.1,而不是实际的主机IP地址?
环境是带有Firefox 4.0.1的Ubuntu 11.04。
维基百科上从/ etc / hosts文件中删除条目的标准答案没有帮助。
解决方法
最终有效的方法是使用IP地址正确更新/ etc / hosts中的条目。
在Ubuntu中,网络管理器配置网络接口后,将执行“ 0”目录中的可执行文件。
此脚本会相应地更新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