阿七

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

iptables NAT

15/12/2018 1867 Views 1 Likes 0 Comments

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 (CC BY-NC-ND 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
vnstat 清零流量重新统计 LudicrousDB - Wordpress 数据库主从热备 Hello World! 忘记关于什么事情了 selinux How to compile ffmpeg on CentOS DirectAdmin面板 删除log

© 2022 阿七 ALL RIGHTS RESERVED | Working

Theme Kratos Made By Seaton Jiang