跟 UMU 一起玩 OpenWRT(入门篇13):改进 autossh 支持多实例

    在之前的文章《跟 UMU 一起玩 OpenWRT(入门篇10):穿透内网》,https://my.oschina.net/umu618/blog/295193,介绍了 autossh 的使用,现在多了一个需求:想在内网打通多条隧道,即让 autossh 能运行多个 ssh 实例。

    首先在 /etc/config/autossh 里增加一个 section,看起来如下:

config autossh
        option gatetime '0'
        option monitorport '0'
        option poll '600'
        option ssh '-i /etc/dropbear/id_rsa -N -T -R 2222:localhost:22 root@Server1'

config autossh
        option gatetime '0'
        option monitorport '0'
        option poll '600'
        option ssh '-i /etc/dropbear/id_rsa -N -T -R 2222:localhost:22 root@Server2'

    然后改进一下 /etc/init.d/autossh,让它支持多实例,给 start_instance() 函数增加两行:

export SERVICE_MATCH_NAME=1
export SERVICE_NAME="$section"

    最终 start_instance() 函数看起来是这样:

start_instance() {
	local section="$1"

	config_get ssh "$section" 'ssh'
	config_get gatetime "$section" 'gatetime'
	config_get monitorport "$section" 'monitorport'
	config_get poll "$section" 'poll'

	export AUTOSSH_GATETIME="${gatetime:-30}"
	export AUTOSSH_POLL="${poll:-600}"
	export SERVICE_MATCH_NAME=1
	export SERVICE_NAME="$section"
	#export SERVICE_DEBUG=1
	service_start /usr/sbin/autossh -M ${monitorport:-20000} -f ${ssh}
}

    注意:这样改是有副作用的,您反复启动多次就知道了……启动的命令是:

/etc/init.d/autossh start

 

转载于:https://my.oschina.net/umu618/blog/849345

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值