2014
11
02
19:33

FreeBSD 11 on Raspberry Pi

Install FreeBSD 11 on a Raspberry Pi

 

It seems a nice project to try out FreeBSD on a Raspberry Pi.

There are ready made images available from FreeBSD.org, so this is not very hard to accomplish. Both for FreeBSD 10 as well as for FreeBSD 11. Feeling wild, I choose for FreeBSD 11 🙂

The image can be downloaded from the FreeBSD ftp-servers.

Bunzip your image and dd it to a SD-card

 

I got the FreeBSD-11.0-CURRENT-arm-armv6-RPI-B-20140811-r269824.img.bz2 but perhaps when you read this there are allready newer images available.

On a Debian GNU/Linux laptop I ran the command:

bunzip2 FreeBSD-11.0-CURRENT-arm-armv6-RPI-B-20140811-r269824.img.bz2

Followed by:

dd if=FreeBSD-11.0-CURRENT-arm-armv6-RPI-B-20140811-r269824.img of=/dev/mmcblk0 bs=1M

Be carefull when you issue this last command, when you got the of= part wrong, you might inreversable destroy things!

Now you have a 1Gb big image on your SD card.

Put the SD card in the Raspberry Pi and power up.

The very first time you boot FreeBSD on your Raspberry Pi it seems to take ages before you get a prompt. This is because FreeBSD is expanding the partion to fill your whole SD card. In my case it was a 8 Gb SD card. I rebooted the thing and now it did not take that long to give you a prompt.

When you have a prompt, press enter and log on as root, with an empty password (just hit Enter on the password prompt).

Now you first need to add a user, make that part of the group “wheel” and give this user a password. This is needed in order to log on to your FreeBSD Raspberry Pi over ssh.

Set fixed address

Default your FreeBSD Raspberry Pi will get its network configuration over DHCP. This is great if you want that, but I like my servers to have fixed addresses.

In /etc/rc.conf you can set the fixed address of the board and add a line with the default router:

ifconfig_ue0=”inet 192.168.0.123 netmask 255.255.255.0″

defaultrouter=”192.168.0.1″

Do not forget to check /etc/resolv.conf to see if this has the right nameserver(s).

Set timezone

Become root.

Make a symbolic link for your timezone to /etc:

ln -s /usr/share/zoneinfo/Europe/Amsterdam /etc/localtime

Update the time on your board;

ntpdate -v -b in.pool.ntp.org

And edit /etc/rc.conf, add the following line:

ntpdate_enable=”YES”

ntpd_enable=”YES”

Configure sshd

 

When your Raspberry Pi is connected to the internet, it is important to harden your sshd_config. The best is to disable password login, only allow public key authentication and only for restricted users. Something like “Match Group wheel” is a good start.

No pkg install

 

Unfortunately, installing pre-compiled binary packages with the new pkg will not work on your Raspberry Pi.

Hardware stability is an issue

 

I own several Raspberry Pies and not all of them are stable. Also the Raspberry Pi is notorious picky about the powersupply cable (USB cable) as well as the powersupply. Problems with the powersupply cable and the powersupply are hard to diagnose.

If you run into problems, the USB cable and the powersupply are the first things to check. I have seen Raspberries that, when powered on, only show a single, red, LED burning, with all the other LEDs are off. This often is the result of a USB-cable or power supply not playing nice with the Rapsberry – even if the same combination have run wihout problems for weeks.

On the other hand, there are also a couple Raspberries running in my network with high uptimes and never have shown any problem …

2014
11
01
23:39

IPv6地址表示方法

对于一个完整的IPv6地址,需要写128位,已经被分成了8段,每段4个字符,也就是说完整地表示一个IPv6地址,需要写32个字母,这是相当长的,并且容易混淆和出错,所以IPv6在地址的表示方法上,是有讲究的,到目前为止,IPv6地址的表示方法分为三种,分别是:

1.首选格式

2.压缩表示

3.IPv4内嵌在IPv6中
下面分别详细介绍这三种IPv6地址表示方法:
1.首选格式

首选格式的表示方法其实没有任何讲究,就是将IPv6中的128位,也就是共32个字符完完整整,一个不漏地全写出来,比如下面就是一些IPv6地址的首选格式表示形式:

0000:0000:0000:0000:0000:0000:0000:0000

0000:0000:0000:0000:0000:0000:0000:0001

2001:0410:0000:1234:FB00:1400:5000:45FF

3ffe:0000:0000:0000:1010:2a2a:0000:0001

FE80:0000:0000:0000:0000:0000:0000:0009

FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF
从上面IPv6地址的首选格式表示中可以看出,每一个地址,都将32个字符全部写了出来,即使地址中有许多个0,或者有许多个F,也都一个不漏地写了出来,由此可见,首选格式只需要将地址完整写出即可,没有任何复杂的变化,但是容易出错。
2.压缩格式

从前面一个IPv6地址表示方法首选格式表示方法中可以看出,一个完整的IPv6地址中,会经常性的出现许多个0,而我们知道,许多时候,0是毫无意义的,0表示没有,写出来,也表示没有,不写,也同样表示没有,那么我们就考虑能否将不影响地址结果的0给省略不写,这样就可以大大节省时间,也方便人们阅读和书写,这样的将地址省略0的表示方法,称为压缩格式。

而压缩格式的表示中,分三种情况,下面来分别介绍三种压缩格式:
第一种情况:

在IPv6中,地址分为8个段来表示,每个段共4个字符,但是一个完整的IPv6地址会经常碰到整个段4个字符全部都为0,所以我们将整个段4个字符全部都为0的使用双冒号::来表示,如果连续多个段全都为0,那么也可以同样将多个段都使用 双冒号::来表示,如果是多个段,并不需要将双冒号写多次,只需要写一次即可,比如一个地址8个段,其中有三个段全都为0,那么我们就将这全为0的三个段共48位用::来表示,再将其它5个段照常写出即可,当计算机读到这样一个不足128位的地址时,比128位少了多少位,就在::的地方补上多少个0,比如上面的::代替为48位,那么计算机就会在这个地址的::位置补上48位的0,这样就正确地将地址还原回去了。

下面来看一些整个段4个字符都为0的IPv6地址使用压缩格式来表示:

例1:

压缩前:

0000:0000:0000:0000:0000:0000:0000:0000

压缩后:

::

说明:可以看出,由于这个地址的8个段全部都为0,所以只用::就将整个地址表示出来,当计算机拿到这个压缩后的地址时,发现比正常的128位少了128位,那么就会在::的地方补上128个0,结果为:

0000:0000:0000:0000:0000:0000:0000:0000

可以看出,计算机还原的地址就是压缩之前的真实地址。
例2:

压缩前:

0000:0000:0000:0000:0000:0000:0000:0001

压缩后:

::0001

说明:可以看出,压缩后的地址比正常的128位少了112位,计算机就会在::的地方补上112个0,结果为:

0000:0000:0000:0000:0000:0000:0000:0001

可以看出,计算机还原的地址就是压缩之前的真实地址。
例3:

压缩前:

2001:0410:0000: 0000:FB00:1400:5000:45FF

压缩后:

2001:0410 :: FB00:1400:5000:45FF

说明:可以看出,压缩后的地址比正常的128位少了32位,计算机就会在::的地方补上32个0,结果为:

2001:0410:0000: 0000:FB00:1400:5000:45FF

可以看出,计算机还原的地址就是压缩之前的真实地址。
例4:

压缩前:

3ffe:0000:0000:0000:1010:2a2a:0000:0001

压缩后:

3ffe::1010:2a2a::0001

说明:当计算机拿到这个压缩后的地址,发现比正常的128位少了64位,计算机就会试图在::的地方补上少了的64个0,但是我们可以看到,压缩后的地址有两个::,而计算机要补上64个0,所以这时补出来的结果很可能是以下几种:

3ffe:0000:1010:2a2a: 0000:0000:0000:0001

或

3ffe:0000:00001010:2a2a::0000:0000:0001

或

3ffe:0000:0000:0000:1010:2a2a:0000:0001

从结果中可以发现,当一个IPv6地址被压缩后,如果计算机出现两个或多个::的时候,计算机在将地址还原时,就可能出现多种情况,这将导致计算机还原后的地址不是压缩之前的地址,将导致地址错误,最终通信失败。

所以,在压缩IPv6地址时,一个地址中只能出现一个::。

 

第二种情况:

在压缩格式的第一种情况的表示中,是在地址中整个段4个字符都为0时,才将其压缩为::来表示,但是在使用第一种情况压缩之后,我们仍然可以看见地址中还存在许多毫无意义的0,比如0001,0410。我们知道,0001中,虽然前面有三个0,但是如果我们将前面的0全部省略掉,写为1,结果是等于0001的,而0410也是一样,我们将前面的0省略掉,写成410,也同样等于0410的,所以我们在省略数字前面的0时,是不影响结果的,那么这个时候,表示IPv6地址时,允许将一个段中前导部分的0省略不写,因为不影响结果。但是需要注意的是,如果0不是前导0,比如2001,我们就不能省略0写成21,因为21不等于2001,所以在中间的0不能省略,只能省略最前面的0。下面来看一些省略前导0的地址表示形式:

例1:

压缩前:

0000:0000:0000:0000:0000:0000:0000:0000

压缩后:

0:0:0:0:0:0:0:0

从结果中可以看出,计算机根本就不需要对这样的地址还原,压缩后的结果和压缩前的结果是相等的。
例2:

压缩前:

0000:0000:0000:0000:0000:0000:0000:0001

压缩后:

0:0:0:0:0:0:0:1

从结果中可以看出,计算机根本就不需要对这样的地址还原,压缩后的结果和压缩前的结果是相等的。
例3:

压缩前:

2001:0410:0000:1234:FB00:1400:5000:45FF

压缩后:

2001:410:0:1234:FB00:1400:5000:45FF

从结果中可以看出,计算机根本就不需要对这样的地址还原,压缩后的结果和压缩前的结果是相等的。
第三种情况:

在前面两种IPv6地址的压缩表示方法中,第一种是在整段4个字符全为0时,才将其压缩后写为::,而第二种是将无意义的0省略不写,可以发现两种方法都能节省时间,方便阅读。第三种压缩方法就是结合前两种方法,既将整段4个字符全为0的部分写成::,也将无意义的0省略不写,结果就可以出现以下一些最方便的表示方法:

例1:

压缩前:

0000:0000:0000:0000:0000:0000:0000:0001

压缩后:

:: 1

可以看到,结合了两种压缩格式的方法,但为简便。
例2:

压缩前:

2001:0410:0000:0000:FB00:1400:5000:45FF

压缩后:

2001:410:: FB00:1400:5000:45FF

可以看到,结合了两种压缩格式的方法,但为简便。

 

3.IPv4内嵌在IPv6中

在网络还没有全部从IPv4过渡到IPv6时,就可能出现某些设备即连接了IPv4网络,又连接了IPv6网络,对于这样的情况,就需要一个地址即可以表示IPv4地址,又可以表示IPv6地址。

因为一个IPv4地址为32位,一个IPv6地址为128位,要让一个IPv4地址表示为IPv6地址,明显已经少了96位,那么就将一个正常的IPv4地址通过增加96位,结果变成128位,来与IPv6通信。在表示时,是在IPv4原有地址的基础上,增加96个0,结果变成128位,增加的96个0再结合原有的IPv4地址,表示方法为

0:0:0:0:0:0:A.B.C.D 或者::A.B.C.D.,如下:

0000: 0000: 0000: 0000:0000:0000:A.B.C.D

9 6 个0 32位

例:

IPv4地址为 138.1.1.1

表示IPv6地址为0:0:0:0:0:0:138.1.1.1

2014
10
24
14:13

解决android 2.x版本pptp vpn不能连接的问题

手里有个LG p350手机,刷机后系统为2.3.7,始终无法vpn,无论是pptp还是openvpn,当然这还得怪我这个有洁癖,什么都喜欢用原生态,手机也是,非得刷原生态ROM,vpn也只喜欢用系统自带的。

好吧,少话废话,直接上android 2.x版本pptp vpn连接的上,却无法访问网络的的解决方法。原因就出在服务端的配置ppp-options文件上,直接注销“require-mppe-128”这个选项,然后在手机里去掉“启用加密”的勾选。OK,再看看,已经连接上,而且也能访问网络了。

如果是android 4.x,最后是把这项打开,手机上也选上“启用加密”。呵呵……

2014
09
14
14:00

Debian7 Wheezy Gnome3找回最大化最小化按钮

直接ALT+F2,输入dconf-editor

org>gnome>shell>overrides>button-layout,把值改成 :

;minimize,maximize,close(包括冒号)

要注意一点,dconf-editor这个命令在终端下输入会提示错误警告,而且不能修改,所以得用ALT+F2才行,具体原因我不知道。

2014
09
10
19:49

android手机刷机

fastboot erase recovery

 

fastboot flash recovery recovery.img

 

fastboot reboot

 

下载ROM与recovery

http://www.clockworkmod.com/rommanager

2014
09
08
09:43

alert root shell login

vi ~/.bashrc

在最后一行插入:

echo ‘ALERT – Root Shell Access (hostname) on:’ `date` `who` | mail -s “Alert: Root Access from `who | cut -d”(” -f2 | cut -d”)” -f1`” admin@youremail.com

 

1、hostname更换成你的服务器hostname

2、admin@youremail.com更换成自己的接收邮件地址

3、服务器必须有发送邮件的功能。如安装了mailx、exim4等服务

 

2014
09
01
12:22

FreeBSD install shadowsocks-libev

cd /usr/ports/net/shadowsocks-libev

make install clean;rehash

ee /etc/rc.conf 加入

shadowsocks_libev_enable=”YES”
shadowsocks_libev_flags=”-c /usr/local/etc/shadowsocks-libev/config.json”

在/usr/local/etc/shadowsocks-libev/config.json中加入

{
“server”:”136.0.16.99″,
“server_port”:1234,             //服务端端口
“local_address”: “127.0.0.1”,
“local_port”:4321,                 //客户端端口
“password”:”password”,      //客户端连接密码
“timeout”:300,
“method”:”aes-256-cfb”     //加密方式
}

然后客户端,在本地,用config.json文件内容对shadowsocks-gui进行相应配置并运行客户端,

shadowsocks-gui下载地址:http://sourceforge.net/projects/shadowsocksgui/files/dist/

最后设置浏览器代理。Chrome 推荐使用 SwitchySharp 切换代理设置。把浏览器代理设为下列参数即可:

协议: socks5

地址: 127.0.0.1

端口: 你填的 local_port

service shadowsocks-libev restart

ok应该可以科学上网了

2014
08
30
09:28

Connect To OpenVPN Over Shadowsocks

按照https://github.com/clowwindy/shadowsocks/wiki/Connect-to-OpenVPN-over-Shadowsocks给的教程;我试了一下,步骤如下:

1、之前安装的OPENVPN服务端 server.conf配置文件里的proto udp 改为 proto tcp

2、openvpn客户端proto udp 也是改为 proto tcp

3、openvpn直接在客户端最后面加入

socks-proxy 127.0.0.1 19999

route 123.xxx.xxx.xxx 255.255.255.255 net_gateway

保存,在服务器重启openvpn 搞定。