linux
  • Introduction
  • Yum
    • 基础yum源的配置
    • 为yum源配置代理
    • Centos指定版本的yum源
    • 环境变量
    • 本地yum源
    • 制作yum源
      • 同步yum源
    • epel源
  • Iptables
    • 基本匹配条件
    • Match-Extensions
      • Addrtype
      • Set
      • TCP
    • Target-Extensions
      • DNAT
      • LOG
    • Iptables规则持久化
    • 连接追踪
  • LVS
    • Ipvsadm命令
  • 磁盘与分区
    • 创建分区
    • 格式化与挂载
    • fstab
    • LVM
      • LVM扩容
    • swap分区
    • tmpfs
  • 网络相关
    • 重命名网卡
    • resolv.conf
    • Tcpdump
    • dig与nslookup
  • Other
    • CPU与内存
    • 进程
      • 僵尸进程
    • SSH密钥登录
    • 用户管理
    • Crontab
  • Nofile
    • 原理
  • 常用软件安装篇
    • MYSQL
    • 系统与内核
      • 指定内核启动
    • NFS
    • Haproxy
    • Keepalived
    • Squid
    • Redsocks
    • Shadowsocks
    • 时钟同步
  • 内存
Powered by GitBook
On this page
  • -j DNAT [options]
  • 示例

Was this helpful?

  1. Iptables
  2. Target-Extensions

DNAT

-j DNAT [options]

常用的options有

  • --to-destination [ipaddr[-ipaddr]][:port[-port]]

这是一个Terminating Target

示例

  • 只变IP

iptables -t nat -I OUTPUT -d 1.1.1.1 --to-destination 172.26.0.4
  • 端口有变

由于只有部分协议(TCP、UDP、DCCP和SCTP)才有端口这个属性,所以在包含有端口时,必须指定协议类型;也就是说,这个包在匹配时,必须要匹配到上述四个扩展中的某一个

iptables -t nat -I OUTPUT -p tcp --to-destination 172.26.0.4:8080

上述的规则就会把从本机上所有进程发出去的TCP包,都转到172.26.0.4:8080去

PreviousTarget-ExtensionsNextLOG

Last updated 5 years ago

Was this helpful?