阿七

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

iptables NAT

15/12/2018 1971Views 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 How to install htop on CentOS 7
DirectAdmin面板 NewWorld主题 适配1.50 君の名は 腾讯云 显示内存不足 1G namesilo 性价比最高的域名注册商 LudicrousDB - Wordpress 数据库主从热备 单词音频合成软件

© 2022 阿七 ALL RIGHTS RESERVED | Working

Theme Kratos Made By Seaton Jiang