DarkNode

Life, the Universe and Everything

PKU 校园网 IPv6 环境下的网络配置

本文发表于:
最后修改于:
分类:network
合计信息量:7.39kb

相关说明

服务器信息:

路由器信息:

服务器的配置

目前 ConoHa 的 De­bian 8.0 64bit 系统尚不能自动绑定 IPv6 地址,所以首先需要绑定 IPv6 地址。从 ConoHa 的控制台查看 IPv4、IPv6 的地址、掩码、网关数据,ConoHa 提供了 17 个 IPv6 地址,随意选择一个即可,随后修改/etc/net­work/in­ter­faces 绑定静态 IP:

$ vi /etc/net­work/in­ter­faces
# This file de­scribes the net­work in­ter­faces avail­able on your sys­tem
# and how to ac­ti­vate them. For more in­for­ma­tion, see in­ter­faces(5).

source /etc/net­work/in­ter­faces.d/*

# The loop­back net­work in­ter­face
auto lo
iface lo inet loop­back
iface lo inet6 loop­back

# The pri­mary net­work in­ter­face
auto eth0
iface eth0 inet6 sta­tic
        ad­dress IPv6 地址
        net­mask 64
        gate­way IPv6 网关
iface eth0 inet sta­tic
        ad­dress IPv4 地址
        net­mask IPv4 掩码
        gate­way IPv4 网关

随后重启服务器即可完成 IP 地址的绑定工作。

接下来安装 Shad­owVPN:

$ echo "deb http://shad­owvpn.org/de­bian wheezy main" >> /etc/apt/sources.list
$ apt-get up­date
$ apt-get in­stall shad­owvpn

修改 Shad­owVPN 的配置文件:

$ vi /etc/shad­owvpn/server.conf 

将 server 设置为::0 以监听 IPv6 地址,将 port 设置为 53 以绕过 QoS 限速,将 mtu 设置为 1412 以适配 IPv6 网络,修改 pass­word 设置一个复杂的密码,根据实例修改 user_to­ken 以提供多用户功能,重启 Shad­owVPN 使设置生效:

$ ser­vice shad­owvpn restart

至此,服务器的配置已经完成。

路由器的配置

路由器使用 Open­Wrt Chaos Calmer 15.05 原版系统,第一次启动时先通过 tel­net 进行访问并修改 root 用户密码,再通过 ssh 登录:

$ tel­net 192.168.1.1
$ passwd
$ exit
$ ssh root@192.168.1.1

在配置前,首先添加软件源,由于 Shad­owVPN 的源尚未添加包签名,故需要关闭包签名检查,进行系统更新,并安装软件包:

$ cat << _EOF_ > /etc/opkg.conf
dest root /
dest ram /tmp
lists_dir ext /var/opkg-lists
op­tion over­lay_root /over­lay
src/gz chaos_calmer_base http://down­loads.open­wrt.org/chaos_calmer/15.05/ar71xx/generic/pack­ages/base
src/gz chaos_calmer_luci http://down­loads.open­wrt.org/chaos_calmer/15.05/ar71xx/generic/pack­ages/luci
src/gz chaos_calmer_pack­ages http://down­loads.open­wrt.org/chaos_calmer/15.05/ar71xx/generic/pack­ages/pack­ages
src/gz chaos_calmer_rout­ing http://down­loads.open­wrt.org/chaos_calmer/15.05/ar71xx/generic/pack­ages/rout­ing
src/gz chaos_calmer_tele­phony http://down­loads.open­wrt.org/chaos_calmer/15.05/ar71xx/generic/pack­ages/tele­phony
src/gz chaos_calmer_man­age­ment http://down­loads.open­wrt.org/chaos_calmer/15.05/ar71xx/generic/pack­ages/man­age­ment
src/gz open­wrt_dist http://open­wrt-dist.source­forge.net/re­leases/ar71xx/pack­ages
src/gz open­wrt_dist_luci http://open­wrt-dist.source­forge.net/re­leases/luci/pack­ages
_EOF_
$ opkg up­date
$ opkg list-upgrad­able | cut -d " " -f1 | xargs -r opkg up­grade
$ opkg in­stall Shad­owVPN Chi­naDNS wget

针对 PKU 校园网络进行 IPv6 配置,修改/etc/con­fig/dhcp 中的如下两段:

$ vi /etc/con­fig/dhcp
con­fig dhcp 'lan'
    op­tion in­ter­face 'lan'
    op­tion start '100'
    op­tion limit '150'
    op­tion lease­time '12h'
    op­tion dhcpv6 're­lay'
    op­tion ndp 're­lay'
    op­tion ra 're­lay'

con­fig dhcp 'wan'
    op­tion in­ter­face 'wan'
    op­tion ig­nore '0'
    op­tion dhcpv6 're­lay'
    op­tion ndp 're­lay'
    op­tion ra 're­lay'
    op­tion mas­ter '1'

配置 Shad­owVPN:

$ vi /etc/con­fig/shad­owvpn
con­fig shad­owvpn
    op­tion con­cur­rency '1'
    op­tion intf 'tun0'
    op­tion server '服务器 IPv6 地址'
    op­tion port '53'
    op­tion user_to­ken '用户 to­ken'
    op­tion pass­word '用户密码'
    op­tion route_mode '1'
    op­tion route_file '/etc/chi­nadns_chn­route.txt'
    op­tion net '10.7.0.1/31'
    op­tion route_mode_save '1'
    op­tion mtu '1412'
    op­tion en­able '1'

配置 Chi­naDNS:

$ vi /etc/con­fig/chi­nadns
con­fig chi­nadns
    op­tion com­pres­sion '1'
    op­tion chn­route '/etc/chi­nadns_chn­route.txt'
    op­tion port '5353'
    op­tion server '114.114.114.114,8.8.4.4'
    op­tion en­able '1'
    op­tion bidi­rec­tional '0'

根据 lsylsy2 的此项目 修改路由表配置文件:

$ vi /etc/chi­nadns_chn­route.txt
1.0.1.0/24
1.0.2.0/23
1.0.8.0/21
1.0.32.0/19
……
223.220.0.0/15
223.240.0.0/13
223.254.0.0/16
223.255.0.0/17

或者是直接下载修改好的版本:

$ wget -O /etc/chi­nadns_chn­route.txt --no-check-cer­tifi­cate https://gist.githubuser­con­tent.com/lsylsy2/fe94ca41a8f52b78772e/raw/e51449a7d76d153d3df6934d285d7871cb0862ae/cidr_merge

并为 Chi­naDNS 添加例外:

$ echo "114.114.114.114/32" >> /etc/chi­nadns_chn­route.txt 

随后修改 dns­masq 的配置,将 Chi­naDNS 设置为 dns­masq 的上游服务器:

$ uci set dhcp.@dns­masq[-1].nore­solv='1'
$ uci delete dhcp.@dns­masq[-1].server
$ uci add_list dhcp.@dns­masq[-1].server='127.0.0.1#5353'
$ uci com­mit dhcp

配置校园网自动登录,修改/etc/rc.lo­cal

$ vi /etc/rc.lo­cal
# Put your cus­tom com­mands here that should be ex­e­cuted once
# the sys­tem init fin­ished. By de­fault this file does noth­ing.

wget -q -Y off -T 10 -t 3 -O /dev/null --no-check-cer­tifi­cate "https://162.105.129.65:5428/ip­gate­way­of­pku?uid=校园网帐号&pass­word=校园网密码&range=2&op­er­a­tion=con­nect&time­out=1"

exit 0

配置校园网保持登录:

$ crontab -e
0 * * * * wget -q -Y off -T 10 -t 3 -O /dev/null --no-check-cer­tifi­cate "https://162.105.129.65:5428/ip­gate­way­of­pku?uid=校园网帐号&pass­word=校园网密码&range=2&op­er­a­tion=con­nect&time­out=1"

配置无线网络,提升无线网络速度上限与信号强度:

$ vi /etc/con­fig/wire­less
con­fig wifi-de­vice 'ra­dio0'
    op­tion type 'mac80211'
    op­tion chan­nel '11'
    op­tion hw­mode '11ng'
    op­tion path 'plat­form/ar934x_wmac'
    op­tion tx­power '30'
    op­tion coun­try 'TW'
    op­tion noscan '1'
    op­tion ht­mode 'HT40'

con­fig wifi-iface
    op­tion de­vice 'ra­dio0'
    op­tion net­work 'lan'
    op­tion mode 'ap'
    op­tion ssid '2.4G 网络 SSID 名称'
    op­tion en­cryp­tion 'psk2+ccmp'
    op­tion key '2.4G 网络 WIFI 密码'

con­fig wifi-de­vice 'ra­dio1'
    op­tion type 'mac80211'
    op­tion hw­mode '11na'
    op­tion path 'pci0000:00/0000:00:00.0'
    op­tion coun­try 'TW'
    op­tion tx­power '30'
    op­tion ht­mode 'HT40'
    op­tion noscan '1'
    op­tion chan­nel '149'

con­fig wifi-iface
    op­tion de­vice 'ra­dio1'
    op­tion net­work 'lan'
    op­tion mode 'ap'
    op­tion ssid '5G 网络 SSID 名称'
    op­tion en­cryp­tion 'psk2+ccmp'
    op­tion key '5G 网络 WIFI 密码'

至此,路由器的配置已经完成。