美文网首页
Iptables 端口转发 port forward

Iptables 端口转发 port forward

作者: 花生Linkin | 来源:发表于2020-01-08 16:13 被阅读0次

    Linux 下配置iptables 实现端口转发。从网卡enp8s0 进, 从网卡enp8s0_priv_mac 出。
    port 5000 -->192.168.100.1:22

    ip_base="192.168.100."
    modprobe iptable_nat
    echo 1 > /proc/sys/net/ipv4/ip_forward
    sleep 1
    ip=$(ip -f inet -o addr show enp8s0|cut -d\ -f 7 | cut -d/ -f 1 | head -n 1)
    iptables -F
    iptables -t nat -F
    iptables -t mangle -F
    iptables -t nat -A POSTROUTING -o enp8s0_priv_mac -j MASQUERADE
    iptables -A INPUT -i enp8s0 -j ACCEPT
    iptables -A FORWARD -i enp8s0 -j ACCEPT
    iptables -A INPUT -i lo -j ACCEPT
    iptables -A FORWARD -i lo -j ACCEPT
    iptables -A OUTPUT -o lo -j ACCEPT

    ssh port 5000 forwarding to CPU A

    iptables -t nat -A PREROUTING -i enp8s0 -p tcp -d ip --dport 5000 -j DNAT --to "{ip_base}1:22"
    iptables -t nat -A PREROUTING -i enp8s0 -p udp -d ip --dport 5000 -j DNAT --to "{ip_base}1:22"
    iptables -t nat -A OUTPUT -o lo -p tcp -d ip --dport 5000 -j DNAT --to "{ip_base}1:22"
    iptables -t nat -A OUTPUT -o lo -p udp -d ip --dport 5000 -j DNAT --to "{ip_base}1:22"

    相关文章

      网友评论

          本文标题:Iptables 端口转发 port forward

          本文链接:https://www.haomeiwen.com/subject/lnssactx.html