新手请教 XSVPS 搭梯子的问题

2015-03-09 21:17:56 +08:00
 gason406
听说这家KVM正在打折于是手贱买了个,结果装了PPTP和SS之后发现都是超时连不上,ssh远程新建了一个帐户搭配myentunnel还是连不上,然后新建了一个ssh端口发现新端口接不通……有没有遇到一样情况的,求指教
另,root远程登录之后ping谷歌百度都是通的……
306 次点击
所在节点    VPS
3 条回复
yywudi
2015-03-10 18:44:09 +08:00
如果你是centos,看一下iptables。
gason406
2015-03-10 21:42:02 +08:00
@yywudi 劳烦求教

这是/etc/sysconfig/iptables的内容
# Ferewall cll configuration written by system-config-firewall
# Manual customization of this file is not recommended.
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT


输入iptables -L返回
Chain INPUT (policy ACCEPT)
target prot opt source destination
ACCEPT all -- anywhere anywhere state RELATED,ESTABLISHED
ACCEPT icmp -- anywhere anywhere
ACCEPT all -- anywhere anywhere
ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:ssh
REJECT all -- anywhere anywhere reject-with icmp-host-prohibited

Chain FORWARD (policy ACCEPT)
target prot opt source destination
REJECT all -- anywhere anywhere reject-with icmp-host-prohibited

Chain OUTPUT (policy ACCEPT)
target prot opt source destination

然后我谷歌了添加端口是
iptables -A INPUT -p tcp --dport xxxx -j ACCEPT
iptables -A OUTPUT -p tcp --dport XXXX -j ACCEPT
但是添加之后上述端口telnet仍然超时
请问我应该怎么做
yywudi
2015-03-10 22:36:31 +08:00
@gason406 首先建议新手直接用iptables -F 或者service iptables stop 清除所有iptables 规则 + 安装fail2ban防止ssh爆破 来先正常使用,然后再好好的学习一下iptables “防火墙” 的规则

以下是我的浅显理解:
iptables 分为INPUT/OUTPUT/FORWARD/NAT 等filter chain

从iptables -L 可以看出,centos默认的iptables INPUT规则只允许ICMP(ping)和22端口的ssh接入,其他的数据包都会被reject (INPUT的最后一条是reject all)

iptables -A 的意思是append,即把这条规则加入到对应的规则链之后,鉴于默认的INPUT最后一条是rejct all,也就是说你添加的一条规则 "iptables -A INPUT -p tcp --dport xxxx -j ACCEPT" 是添加在reject all之后,那么iptables按照依次执行的顺序,在允许这个指定端口tcp input的rule 之前 数据包已经被reject了,所以这里正确的应该是用iptables -I ,也就是插入一条规则到INPUT chain的最前面。(话说你说的telnet超时是啥意思?笔误应该是ssh? 如果真的是telnet,除了iptables允许通过,起码得启动telnet服务吧?)

当然,如果你开SS,那么SS的端口也可以用iptables -I来添加 。 ——如果一开始用iptables -F清空了,那么用-A也是可以的。或者你可以先用iptables -D 删除掉reject all这条rule。

如果是PPTP VPN,因为涉及到虚拟网卡ppp0,需要有一条FORWARD的iptables 规则来让pptp 客户端ip过来的数据包正确转发,这个我想任何一个baidu/google 找到的所谓一键脚本里面都会有相应的iptables规则,比如:iptables -A FORWARD -s 10.0.0.0/8 -p tcp -m tcp --tcp-flags FIN,SYN,RST,ACK SYN -j TCPMSS --set-mss 1356
抛开iptables,想要正常使用pptp,还需要修改/etc/sysctrl.conf net.ipv4.ip_forward = 1

OUTPUT规则是管这个VPS对外发送的数据包的,一般不会做什么限制

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/175645

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX