Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow hostname in server address #30

Closed
wants to merge 1 commit into from

Conversation

Projects
None yet
9 participants
@CzBiX
Copy link

commented Sep 10, 2016

No description provided.

@CzBiX

This comment has been minimized.

Copy link
Author

commented Sep 10, 2016

不是很明白。因为部分用户是用 UDP 转发 DNS 而无法在启动前解析域名?

我是直接使用 ChinaDNS 当作 upstream DNS server,工作良好。
由于一部分功能的限制而一刀切有点因噎废食了。
个人感觉在 Server Address 输入框旁加上限制说明就可以了。

@CzBiX CzBiX closed this Sep 10, 2016

@wongsyrone

This comment has been minimized.

Copy link

commented Sep 10, 2016

You'd better ask @aa65535

@lixingcong

This comment has been minimized.

Copy link

commented Sep 10, 2016

先有鸡还是先有蛋的问题。。。

先获取到ip还是先获取到域名的问题。。

@CzBiX

This comment has been minimized.

Copy link
Author

commented Sep 10, 2016

我大概明白了,除了使用 SS 转发 DNS 请求外,还要把服务器 IP 地址加到排除列表里。。。
我测试能正常工作是因为我已经手动把服务器地址加到了 Bypassed IP 里。

也就是要给 ss-rules 加上解析域名并添加到 ss_spec_dst_sp 的功能才行。

shadowsocks/openwrt-shadowsocks#124

@aa65535

This comment has been minimized.

Copy link
Collaborator

commented Sep 10, 2016

有这么多人不理解,那就解释一下吧。

其实 spec 之前有几个版本是支持填写域名的,但是就如上面所说,需要 ss-rules 解析域名成 IP 后添加到Bypassed IP 里,否则 ss-redir 是无法正常工作的(数据包在本地死循环出不去了)。
问题是解析域名成 IP 这个功能很不稳定,因为在路由器刚启动的时候是没有联网的,所以 shadowsocks 无法正常自启动,或者正常联网的情况下,DNS 本身是依赖 shadowsocks 转发的,所以在 shadowsocks 没有启动之前却需要使用 shadowsocks 去解析域名,这个就是「先有鸡还是先有蛋的问题」。
使用域名的毕竟少,即使有也可以自己 ping 一下获取到 IP,这个 IP 一般是不会变动的,也不至于很麻烦。

@fjct

This comment has been minimized.

Copy link

commented Feb 11, 2017

你好,

我用的是电信光纤+openwrt+DDNS,IP老是自动更换(不重启也经常被动更换)

跪求能不能用域名输入SS服务器地址?

Fred

@cokebar

This comment has been minimized.

Copy link

commented Feb 11, 2017

@fjct 你这种情况,更好的解决办法是,放弃开机自启,写一个脚本,开机延迟一段时间执行一次,尝试获取服务器IP,获取成功,就脚本更新shadowsocks设置后启动。并且每过一个域名TTL的时间,检测一次IP是否变化,如果变了,更新shadowsocks设置并重启。针对DDNS需要一套IP变化检测机制,单单支持能填域名是不够的,易造成开机自启失败,同时IP变化时候需要额外处理。

@ayanamist

This comment has been minimized.

Copy link

commented Nov 17, 2017

这个确实太因噎废食了,如果只是因为dns解析的问题,完全可以用iptables -I OUTPUT -m owner --pid_owner %d -j RETURN的方式把ss-redir自己的所有流量全部优先跳过,这样根本不需要知道ss-server的ip

@aa65535

This comment has been minimized.

Copy link
Collaborator

commented Nov 17, 2017

@ayanamist 有不少固件是没有 owner 这个 module 的,而且也没法安装。

@edison0354

This comment has been minimized.

Copy link

commented Feb 13, 2018

#!/usr/bin/env ash
for i in `uci show shadowsocks | grep alias | sed -r 's/.*\[(.*)\].*/\1/'`
do
server=$(uci get shadowsocks.@servers[${i}].alias)
uci set shadowsocks.@servers[${i}].server=`ping -c 1 $server | awk -F"[()]" '/PING/{print $2}'`
done

我这边买的服务,ip似乎偶尔会变,只能用域名做配置……
于是这样写个脚本,alias都填成域名,改成一行直接丢进crontab里面每天自动更新一遍ip似乎就可以了?
顺便似乎也可以写个脚本自动ping www.google.com,失败的话就自动切另一条线路?

@panda-mute

This comment has been minimized.

Copy link

commented Mar 6, 2018

#!/bin/sh

restart=0
for i in `uci show shadowsocks | grep alias | sed -r 's/.*\[(.*)\].*/\1/'`
do
	server=$(uci get shadowsocks.@servers[${i}].alias)
	result=$(nslookup $server)

	new_ip=$(echo "${result}" | tail -n +3 | awk -F" " '/^Address 1/{ print $3}')
	if [ -n "$new_ip" ]; then
		logger -t shadowsocks "nslookup $server -> $new_ip"
		old_ip=$(uci get shadowsocks.@servers[${i}].server)
		if [ "$old_ip" != "$new_ip" ]; then
			logger -t shadowsocks "detect $server ip address change ($old_ip -> $new_ip)"
			restart=1
			uci set shadowsocks.@servers[${i}].server=${new_ip}
		fi
	else
		logger -t shadowsocks "nslookup $server fail"
	fi
done

if [ $restart -eq 1 ]; then
	logger -t shadowsocks "restart for server ip address change"
        uci commit shadowsocks
	/etc/init.d/shadowsocks restart
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.