阿七

  • HOME
  • CATEGORY
    • TECH
    • ENG
    • VIDEO
    • Image
    • MUSIC
  • Baidu
  • MY LIST
LOVE LASTS FOREVER
  1. Home
  2. TECH
  3. Text

iptables NAT

15/12/2018 2042Views 1Likes 0Comments

enable kernel ipv4 forward

add net.ipv4.ip_forward=1 to sysctl.conf

1
2
vi /etc/sysctl.conf
sysctl -p

add tcp and udp forward to iptables

1
2
3
4
iptables -t nat -A PREROUTING -p tcp --dport PORT -j DNAT --to-destination DSTIP
iptables -t nat -A PREROUTING -p udp --dport PORT -j DNAT --to-destination SOURIP
iptables -t nat -A POSTROUTING -p tcp -d DSTIP --dport PORT -j SNAT --to-source LOCIP
iptables -t nat -A POSTROUTING -p udp -d DSTIP --dport PORT -j SNAT --to-source LOCIP

save iptables configuration and set boot in Debian

1
2
3
iptables-save /etc/iptables.up.rules
echo -e '#!/bin/bash\n/sbin/iptables-restore  /etc/iptables.up.rules' /etc/network/if-pre-up.d/iptables
chmod +x /etc/network/if-pre-up.d/iptables
Licensed under 知识共享署名 4.0 国际许可协议
Tag: linux
Last:15/12/2018

frank

Love Lasts Forever

Like
< PREV
NEXT >

Comment

取消回复

frank

Love Lasts Forever

New Hot Rand
New Hot Rand
好久没更新了 DirectAdmin 去掉邮件队列 Debian Directadmin 中设置 wordpress 最全的伪静态配置 vnstat 清零流量重新统计 忘记关于什么事情了 selinux DirectAdmin面板 删除log
腾讯云 显示内存不足 1G vnstat 清零流量重新统计 How to compile ffmpeg on CentOS WordPress 全站更换 https 被hao123 hao2345 hao254等主页劫持解决方法 Solutions of DirectAdmin

© 2022 阿七 ALL RIGHTS RESERVED | Working

Theme Kratos Made By Seaton Jiang