V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
通过以下 Referral 链接购买 DigitalOcean 主机,你将可以帮助 V2EX 持续发展
DigitalOcean - SSD Cloud Servers
gason406
V2EX  ›  VPS

新手请教 XSVPS 搭梯子的问题

  •  
  •   gason406 · 2015-03-09 21:17:56 +08:00 · 292 次点击
    这是一个创建于 3326 天前的主题,其中的信息可能已经有所发展或是发生改变。
    听说这家KVM正在打折于是手贱买了个,结果装了PPTP和SS之后发现都是超时连不上,ssh远程新建了一个帐户搭配myentunnel还是连不上,然后新建了一个ssh端口发现新端口接不通……有没有遇到一样情况的,求指教
    另,root远程登录之后ping谷歌百度都是通的……
    3 条回复    2015-03-10 22:36:31 +08:00
    yywudi
        1
    yywudi  
       2015-03-10 18:44:09 +08:00 via Android
    如果你是centos,看一下iptables。
    gason406
        2
    gason406  
    OP
       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
        3
    yywudi  
       2015-03-10 22:36:31 +08:00   ❤️ 1
    @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对外发送的数据包的,一般不会做什么限制
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1235 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 23:19 · PVG 07:19 · LAX 16:19 · JFK 19:19
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.