2012年4月

经过昨天的实践,终于搞定Ubuntu共享WiFi功能,而且不是Ad-hoc模式。从此“二奶”可以作为无线中继使用(这里指的是在Ubuntu系统下)。参考教程:
Ubuntu共享WiFi(AP)给Android/更新方法二 http://weibin.me/538

首先很重要的是,要确定无线网卡驱动是否支持master mode。如果不支持,就别想了。然后就可以按照教程安装并设置hostapd和dnsmasq。根据教程,写了个脚本,方便启动或关闭该功能。第一次写比较长的Shell脚本,所以该脚本还是不太完善,但基本可用。要注意,/etc/dnsmasq.conf还是要手动修改。脚本如下:

#!/bin/sh
# begin file: sharewifi

# Setup wireless AP, share the Internet from interface0 to interface1
# USAGE: sharewifi [ start | stop ] interface0 interface1
# EXAMPLE: sharewifi start wlan1 wlan0

help( )
{
cat << HELP
Setup wireless AP, share the Internet from interface0 to interface1
USAGE: sharewifi [ help | start | stop ] interface0 interface1
EXAMPLE: sharewifi start wlan1 wlan0
HELP
exit 0
}

start( )
{
echo Starting share wifi ......
echo Share Internet $port_in to $port_out

# Configure iptable rules
iptables -F
iptables -t nat -A POSTROUTING -s 192.168.7.0/24 -o $port_in -j MASQUERADE
iptables -A FORWARD -s 192.168.7.0/24 -o $port_in -j ACCEPT
iptables -A FORWARD -d 192.168.7.0/24 -m conntrack --ctstate ESTABLISHED,RELATED -i $port_in -j ACCEPT

# Log the message of route
#iptables -A INPUT -m conntrack --ctstate NEW -p tcp --dport 80 -j LOG --log-prefix "NEW_HTTP_CONN: "

# Save iptable rules
sh -c "iptables-save > /etc/iptables.rules"

# Configure hostapd
hostapd_conf=/etc/hostapd/hostapd.conf
[ -f $hostapd_conf ] && rm $hostapd_conf
echo >> $hostapd_conf interface=$port_out
echo >> $hostapd_conf driver=nl80211
echo >> $hostapd_conf ssid=AO522-Tether
echo >> $hostapd_conf channel=1
echo >> $hostapd_conf hw_mode=g
echo >> $hostapd_conf auth_algs=1
echo >> $hostapd_conf wpa=3
echo >> $hostapd_conf wpa_passphrase=1234567890
echo >> $hostapd_conf wpa_key_mgmt=WPA-PSK
echo >> $hostapd_conf wpa_pairwise=TKIP CCMP
echo >> $hostapd_conf rsn_pairwise=CCMP
chmod 755 $hostapd_conf

# Configure /etc/dnsmasq.conf
#interface=wlan0
#bind-interfaces #这个是只监听wlan0,没有之会检测所有卡
#except-interface=lo
#dhcp-range=10.1.1.10,10.1.1.110,6h #设置dhcp地址范

killall named
killall hostapd
ifconfig $port_out 192.168.7.1
hostapd -B $hostapd_conf
/etc/init.d/dnsmasq restart

echo Sucess share wifi

exit 0
}

stop( )
{
echo Stopping share wifi ......
echo Stop share Internet $port_in to $port_out

# Configure iptable rules
iptables -F

# Log the message of route
#iptables -A INPUT -m conntrack --ctstate NEW -p tcp --dport 80 -j LOG --log-prefix "NEW_HTTP_CONN: "

# Save iptable rules
sh -c "iptables-save > /etc/iptables.rules"

# Configure hostapd
hostapd_conf=/etc/hostapd/hostapd.conf
[ -f $hostapd_conf ] && rm $hostapd_conf

# Configure /etc/dnsmasq.conf

killall named
killall hostapd
ifconfig $port_out down
ifconfig $port_out del 192.168.7.1
ifconfig $port_out up

echo Sucess stop share wifi

exit 0
}
#port_in is the network interface which connected to Internet, and default wlan1.
port_in=wlan1

#port_out is the network interface which will be setup AP, and default wlan0.
port_out=wlan0

if [ -n "$2" ]; then
port_in=$2

if [ -n "$3" ]; then
port_out=$3
fi
fi

case "$1" in
"help" )
help ;;
"start" )
start ;;
"stop" )
stop ;;
*)
help ;;
esac

# end file: sharewifi

PS. “二奶”升级到Lubuntu 12.04 LTS,感觉更好用了~

厦门,尤其是鼓浪屿,本来作为环中国旅游的第一站,由于约定跟前度一起去而没去。跟前度分手后,后悔当初没去,还以为没机会了。想不到一个冲动的决定,就拉着豆丁度过了梦幻般的两天(2012-04-22至2012-04-23)。缘份(Fate)、命运(Disteny)、天注定(It is written)?都解析不了这浪漫的事情。

如果说珠海是浪漫之城,那鼓浪屿就是维纳斯天堂。一个直径才一两公里的小岛,遍布各种西式风格的古旧房子,各种特色小店,无论走到哪,都有惊喜;各种特色小吃、海鲜,无论吃到哪,都有新发现;各种风格主题小旅馆,无论住到哪,都那么写意…

不是攻略的攻略

在鼓浪屿唯一的行程就是“迷路”,漫无目的地游走于大街小巷,感受她的气息,发现她的美。岛上的景点,一个都没去,取而代之的是拿着印章本,去偶遇一个个小店。到店里盖个章,看看那些小饰品,或者写个明信片(没写一封明信片,有点遗憾),比计划着去这去那的好玩多了。当然,最好不要去沙滩,以免破坏一切的美好。

交通与住宿

在厦门机场有大巴直达鼓浪屿渡头。上岛的船票是包来回的,要保管好。岛上的旅馆一般都可以网上订房,但是不要相信淘宝。比较好的旅馆都有自己的官网,可以直接联系老板。为了买到便宜机票和找到好房间,最好提前10天预订。

吃在岛上

这个还是随缘吧。网上推荐那些店,感觉只是一般般。反正看到啥喜欢的就吃啥。

收获与感受

其实这次厦门之旅,还逛了南普陀寺和厦门大学,但是都没什么看头。值得留恋的,只有鼓浪屿。对比上一次的环中国之旅,感受最深的是,一个人的旅行与两个人的旅游,差别是很大的!拖着所爱的人,在路上嬉戏,谈情,是一种幸福!

期待已久的厦门之旅结束了,下一次,要拖着豆丁去哪里呢?乌镇?丽江?还是……其实,我希望是“家”。

PS. 在微博的感言:

错过,可能是未到的相遇;失去,或者是期待的拥有;迷路,也许是憧憬的出口…文艺青年、小资青年、恋爱青年,还是大龄青年,都适合在鼓浪屿邂逅一家小店、留恋一条小巷、寻找一个小印章、发现一朵小花、偶遇一只小猫、踏过一个小沙滩、睡上一间小民宿、拖着一只小手、谈着一段小感情…最后不舍这小岛~

再PS. 感想这东西,还是要趁热打铁。断断续续地写,读起来都变味了。