admin 发布的文章

以前一段时间在openwrt上配置了autossh,手动启动它测试的时候一切正常。但是有一次openwrt重启了,autossh作为自动启动服务在开机启动时,老是在日志里报:

 user.info autossh[pid]: ssh exited with error status 1; restarting ssh

而且对端服务器一直报错:

sshd[pid]: Connection reset by [IP] port [port] [preauth]

就这样一直报错,连接不成功。但是手工重启一下autossh服务又一切正常了。一直比较奇怪。后来在
https://github.com/openwrt/packages/issues/5559
看到有朋友和我一样的问题,找到了原因所在。

autossh在开机启动的时候,找不到$HOME环境变量,默认从根目录下的.ssh中寻找known_hosts 文件进行主机认证。但是根目录下没有这个文件夹。就造成连接不成功了。所以,解决办法就在/etc/init.d/autossh 文件里手工把环境变量写进去。

export HOME=/root

这样,重启的时候就可以自动连接了。至于为什么启动的时候找不到这个环境变量,就没有深究了。

压缩

tar -zcvf /path/to/file.tar.gz file

解压

tar -zxvf /path/to/file.tar.gz /path/to

压缩加密

tar -zcvf - file | openssl aes-256-cbc -salt -k password -out /path/to/file.tar.gz

解密解压

openssl aes-256-cbc -d -k password -salt -in /path/to/file.tar.gz | tar zxvf -

上面的加密与解密操作在相同版本的openssl操作是没有问题的,但是在不同的版本(比如1.0.2和1.1.0版本之间)对于密钥和IV的生成方法有差异,所以在不同版本之间加密解密就会有问题。所以,在不同版本之间采用AES加解密的时候,需要使用参数支持指定密钥和IV,而不是让openssl自动生成,例子如下:

压缩加密

tar -zcvf - file | openssl aes-256-cbc -K 12345678901234567890 -iv 12345678 -out /path/to/file.tar.gz

解密解压

openssl aes-256-cbc -d -K 12345678901234567890 -iv 12345678 -in /path/to/file.tar.gz | tar zxvf -

在这里,注意AES算法的密钥和初始向量都是128位的,这里-K和-iv后的参数都是16进制表示的,最大长度为32。 即-iv 12345678 指定的初始向量在内存中为 | 12 34 56 78 12 34 56 78 00 00 00 00 00 00 00 00 |。

最近电信更新了系统,开通了ipv6的支持,路由拨号后,可能获得一个/60的前缀。这个时候参考网上的一些设置教程,大多是通过中继的设置就不太适合了。

可以获取dhcpv6-pd的情况下,在openwrt下设置其实非常简单:
1、WAN口设置好PPPOE后保持默认设置;

2、WNA6也保持默认设置,如图:
20181102101947.png

3、LAN口的IPV6设置为RA:服务器模式,DHCPv6:服务器模式,NDP:禁用,如下图:
20181102102240.png

4、最后检查 /etc/config/network 文件中的 config interface 'wan' 段下面:

option ipv6 'auto'

PS:如果上面设置还有问题,在接口界面把IPv6 ULA前缀设成空白:
20181102102830.png

这样就可以了,不用像网上教程说的那么麻烦的,很多教程基本上是为不能获得前缀的情况下准备的。

If you are debugging IPTables, it is handy to be able to trace the packets while it traverses the various chains. I was trying to find out why port forwarding from the external NIC to a virtual machine attached to a virtual bridge device was not working.

You need to perform the following preparations:

Load the (IPv4) netfilter log kernel module:

# modprobe nf_log_ipv4

Enable logging for the IPv4 (AF Family 2):

# sysctl net.netfilter.nf_log.2=nf_log_ipv4

reconfigure rsyslogd to log kernel messages (kern.*) to /var/log/messages:

# cat /etc/rsyslog.conf | grep -e "^kern"
kern.*;*.info;mail.none;authpriv.none;cron.none                /var/log/messages

restart rsyslogd:

# systemctl restart rsyslog

Now check the raw tables – you’ll see that there are already entries coming from firewalld:

# iptables -t raw -L
Chain PREROUTING (policy ACCEPT)
target prot opt source destination
PREROUTING_direct all -- anywhere anywhere

Chain OUTPUT (policy ACCEPT)
target prot opt source destination
OUTPUT_direct all -- anywhere anywhere

Chain OUTPUT_direct (1 references)
target prot opt source destination

Chain PREROUTING_direct (1 references)
target prot opt source destination

We’ll want to add our tracing rules before the existing rules. In this example we’ll trace everything related to HTTP (port 80)

# iptables -t raw -j TRACE -p tcp --dport 80 -I PREROUTING 1
# iptables -t raw -j TRACE -p tcp --dport 80 -I OUTPUT 1

The rules now look as follows:

# iptables -t raw -L
Chain PREROUTING (policy ACCEPT)
target prot opt source destination
TRACE tcp -- anywhere anywhere tcp dpt:http
PREROUTING_direct all -- anywhere anywhere

Chain OUTPUT (policy ACCEPT)
target prot opt source destination
TRACE tcp -- anywhere anywhere tcp dpt:http
OUTPUT_direct all -- anywhere anywhere

Chain OUTPUT_direct (1 references)
target prot opt source destination

Chain PREROUTING_direct (1 references)
target prot opt source destination

Now access to that specific machine’s TCP port 80 are logged to /var/log/messages:

# tail /var/log/messages
May 27 19:57:54 storm3 kernel: TRACE: mangle:PRE_public:rule:3 IN=em1 OUT= MAC=ec:f4:bb:f1:4e:f0:00:25:46:70:2e:41:08:00 SRC=10.36.7.11 DST=10.32.105.30 LEN=64 TOS=0x00 PREC=0x00 TTL=59 ID=10953 DF PROTO=TCP SPT=54451 DPT=80 SEQ=1779626624 ACK=0 WINDOW=65535 RES=0x00 SYN URGP=0 OPT (020404D8010303050101080A124E9DB70000000004020000)
May 27 19:57:54 storm3 kernel: TRACE: mangle:PRE_public_allow:return:1 IN=em1 OUT= MAC=ec:f4:bb:f1:4e:f0:00:25:46:70:2e:41:08:00 SRC=10.36.7.11 DST=10.32.105.30 LEN=64 TOS=0x00 PREC=0x00 TTL=59 ID=10953 DF PROTO=TCP SPT=54451 DPT=80 SEQ=1779626624 ACK=0 WINDOW=65535 RES=0x00 SYN URGP=0 OPT (020404D8010303050101080A124E9DB70000000004020000)
May 27 19:57:54 storm3 kernel: TRACE: mangle:PRE_public:return:4 IN=em1 OUT= MAC=ec:f4:bb:f1:4e:f0:00:25:46:70:2e:41:08:00 SRC=10.36.7.11 DST=10.32.105.30 LEN=64 TOS=0x00 PREC=0x00 TTL=59 ID=10953 DF PROTO=TCP SPT=54451 DPT=80 SEQ=1779626624 ACK=0 WINDOW=65535 RES=0x00 SYN URGP=0 OPT (020404D8010303050101080A124E9DB70000000004020000)
May 27 19:57:54 storm3 kernel: TRACE: mangle:PREROUTING:policy:4 IN=em1 OUT= MAC=ec:f4:bb:f1:4e:f0:00:25:46:70:2e:41:08:00 SRC=10.36.7.11 DST=10.32.105.30 LEN=64 TOS=0x00 PREC=0x00 TTL=59 ID=10953 DF PROTO=TCP SPT=54451 DPT=80 SEQ=1779626624 ACK=0 WINDOW=65535 RES=0x00 SYN URGP=0 OPT (020404D8010303050101080A124E9DB70000000004020000)
May 27 19:57:54 storm3 kernel: TRACE: nat:PREROUTING:rule:1 IN=em1 OUT= MAC=ec:f4:bb:f1:4e:f0:00:25:46:70:2e:41:08:00 SRC=10.36.7.11 DST=10.32.105.30 LEN=64 TOS=0x00 PREC=0x00 TTL=59 ID=10953 DF PROTO=TCP SPT=54451 DPT=80 SEQ=1779626624 ACK=0 WINDOW=65535 RES=0x00 SYN URGP=0 OPT (020404D8010303050101080A124E9DB70000000004020000)
May 27 19:57:54 storm3 kernel: TRACE: nat:PREROUTING_direct:rule:1 IN=em1 OUT= MAC=ec:f4:bb:f1:4e:f0:00:25:46:70:2e:41:08:00 SRC=10.36.7.11 DST=10.32.105.30 LEN=64 TOS=0x00 PREC=0x00 TTL=59 ID=10953 DF PROTO=TCP SPT=54451 DPT=80 SEQ=1779626624 ACK=0 WINDOW=65535 RES=0x00 SYN URGP=0 OPT (020404D8010303050101080A124E9DB70000000004020000)
May 27 19:57:54 storm3 kernel: TRACE: mangle:FORWARD:rule:1 IN=em1 OUT=virbr1 MAC=ec:f4:bb:f1:4e:f0:00:25:46:70:2e:41:08:00 SRC=10.36.7.11 DST=192.168.101.10 LEN=64 TOS=0x00 PREC=0x00 TTL=58 ID=10953 DF PROTO=TCP SPT=54451 DPT=80 SEQ=1779626624 ACK=0 WINDOW=65535 RES=0x00 SYN URGP=0 OPT (020404D8010303050101080A124E9DB70000000004020000)
May 27 19:57:54 storm3 kernel: TRACE: mangle:FORWARD_direct:return:1 IN=em1 OUT=virbr1 MAC=ec:f4:bb:f1:4e:f0:00:25:46:70:2e:41:08:00 SRC=10.36.7.11 DST=192.168.101.10 LEN=64 TOS=0x00 PREC=0x00 TTL=58 ID=10953 DF PROTO=TCP SPT=54451 DPT=80 SEQ=1779626624 ACK=0 WINDOW=65535 RES=0x00 SYN URGP=0 OPT (020404D8010303050101080A124E9DB70000000004020000)
May 27 19:57:54 storm3 kernel: TRACE: mangle:FORWARD:policy:2 IN=em1 OUT=virbr1 MAC=ec:f4:bb:f1:4e:f0:00:25:46:70:2e:41:08:00 SRC=10.36.7.11 DST=192.168.101.10 LEN=64 TOS=0x00 PREC=0x00 TTL=58 ID=10953 DF PROTO=TCP SPT=54451 DPT=80 SEQ=1779626624 ACK=0 WINDOW=65535 RES=0x00 SYN URGP=0 OPT (020404D8010303050101080A124E9DB70000000004020000)
May 27 19:57:54 storm3 kernel: TRACE: filter:FORWARD:rule:7 IN=em1 OUT=virbr1 MAC=ec:f4:bb:f1:4e:f0:00:25:46:70:2e:41:08:00 SRC=10.36.7.11 DST=192.168.101.10 LEN=64 TOS=0x00 PREC=0x00 TTL=58 ID=10953 DF PROTO=TCP SPT=54451 DPT=80 SEQ=1779626624 ACK=0 WINDOW=65535 RES=0x00 SYN URGP=0 OPT (020404D8010303050101080A124E9DB70000000004020000)

周杰伦 - 安静

词/曲:周杰伦

只剩下钢琴陪我

弹了一天

睡着的大提琴

安静的旧旧的

我想你已表现的

非常明白

我懂我也知道

你没有舍不得

你说你也会难过

我不相信

牵着你陪着我

也只是曾经

希望他是真的

比我还要爱你

我才会逼自己离开

你要我说多难堪

我根本不想分开

为什么还要我用

微笑来带过

我没有这种天份

包容你也接受他

不用担心的太多

我会一直好好过

你已经远远离开

我也会慢慢走开

为什么我连分开

都迁就着你

我真的没有天份

安静的没这么快

我会学着放弃你

是因为我太爱你

只剩下钢琴陪我

弹了一天

睡着的大提琴

安静的旧旧的

我想你已表现的

非常明白

我懂我也知道

你没有舍不得

你说你也会难过

我不相信

牵着你陪着我

也只是曾经

希望他是真的

比我还要爱你

我才会逼自己离开

你要我说多难堪

我根本不想分开

为什么还要我用

微笑来带过

我没有这种天份

包容你也接受他

不用担心的太多

我会一直好好过

你已经远远离开

我也会慢慢走开

为什么我连分开

都迁就着你

我真的没有天份

安静的没这么快

我会学着放弃你

是因为我太爱你

你要我说多难堪

我根本不想分开

为什么还要我用

微笑来带过

我没有这种天份

包容你也接受他

不用担心的太多

我会一直好好过

你已经远远离开

我也会慢慢走开

为什么我连分开

都迁就着你

我真的没有天份

安静的没这么快

我会学着放弃你

是因为我太爱你