Distributions
Ubuntu
Fedora
CentOS
中文资源站
网易开源镜像站
iloveyou
V2EX  ›  Linux

求个适合web服务器的iptables配置,我参考下。用命令行直接drop掉22端口,那我的ssh链接就断了,所以需要直接改配置文件再重启。

  •  
  •   iloveyou · Feb 15, 2013 · 3912 views
    This topic created in 4842 days ago, the information mentioned may be changed or developed.
    7 replies    1970-01-01 08:00:00 +08:00
    lusin
        1
    lusin  
       Feb 15, 2013
    先将22端口开通再drop
    va3rrw
        2
    va3rrw  
       Feb 15, 2013   ❤️ 1
    aveline
        3
    aveline  
       Feb 15, 2013   ❤️ 1
    iptables-save > firewall
    然后修改 firewall 这个文件
    修改完之后 iptables-restore < firewall 即可
    iloveyou
        4
    iloveyou  
    OP
       Feb 16, 2013
    @aveline 不是很懂 感谢送到
    imstand
        5
    imstand  
       Feb 16, 2013   ❤️ 1
    首先修改配置文件
    vi /etc/ssh/sshd_config
    找到#Port 22一段,这里是标识默认使用22端口,修改为如下:
    Port 22
    Port 50000
    然后保存退出
    执行/etc/init.d/sshd restart
    这样SSH端口将同时工作与22和50000上。

    1. [root@srv6 ~]# iptables -t nat -A PREROUTING -p tcp -m tcp --dport 80 -j REDIRECT --to-ports 8080
    2. [root@srv6 ~]# iptables -t nat -A PREROUTING -p udp -m udp --dport 80 -j REDIRECT --to-ports 8080
    sillyousu
        6
    sillyousu  
       Feb 16, 2013   ❤️ 1
    http://wiki.debian.org/iptables

    这个配置规则就差不多了。按照需要改端口,再添加一些自己需要的。

    把上面iptables的规则保存在一个文件里面,例如保存在 /etc/iptables/iptables.rules

    然后用下面的命令

    $ sudo iptables-restore < /etc/iptables/iptables.rules
    iloveyou
        7
    iloveyou  
    OP
       Feb 16, 2013
    @sillyousu thanks
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1197 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 34ms · UTC 23:25 · PVG 07:25 · LAX 16:25 · JFK 19:25
    ♥ Do have faith in what you're doing.