【发布时间】:2011-06-14 12:59:23
【问题描述】:
知道如何避免 myIpAddress() 总是返回 127.0.0.1,而不是实际的主机 IP 地址吗?
环境是 Ubuntu 11.04 和 Firefox 4.0.1。
Wikipedia 从 /etc/hosts 文件中删除条目的标准答案没有帮助。
【问题讨论】:
标签: proxy ubuntu-11.04 pac
知道如何避免 myIpAddress() 总是返回 127.0.0.1,而不是实际的主机 IP 地址吗?
环境是 Ubuntu 11.04 和 Firefox 4.0.1。
Wikipedia 从 /etc/hosts 文件中删除条目的标准答案没有帮助。
【问题讨论】:
标签: proxy ubuntu-11.04 pac
最终奏效的是使用 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
【讨论】: