当前位置: 首页 > article >正文

linux 配置端口转发

0x00 概述

某些应用做了负载均衡,将 https 443 和 syslog 514 映射出去。但是由于linux某些账户无法在1000以下的端口启动服务,所以应用默认在单个node节点启动的端口可能是大于1000的,例如1443 和 1514,这就需要在负载上配置 域名:443 指向应用 node:1443 或者 域名:443 指向node:443,再通过node本地端口转发将443流量转发到1443。

本文对主要介绍如何利用本地墙做本地端口转发,即使iptables关闭也生效。

0x00 实践

对没做端口转发机器端口扫描:

nmap -vv 10.111.10.11 -sU -p 1514,514
PORT     STATE         SERVICE       REASON                                                                                                                  
514/udp  closed        syslog        port-unreach ttl 61                                                                                                     
1514/udp open|filtered fujitsu-dtcns no-response             

   

手动添加端口转发

配置开机自动加载端口转发

iptables -t nat -A PREROUTING -p udp --dport 514 -j REDIRECT --to-port 1514
iptables-save > /etc/iptable.v4

vi /etc/systemd/system/portmap.service
[Unit]
Description=portmap rules
DefaultDependencies=no
After=network.service

[Service]
Type=oneshot
ExecStart=/bin/bash -c '/sbin/iptables-restore < /etc/iptable.v4'
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target

配置开机自启动(即使防火墙关闭也不受影响)

systemctl daemon-reload && systemctl enable portmap.service

在10.111.10.11 检查端口映射:

 iptables -t nat -L -n -v                                                                                                                
Chain PREROUTING (policy ACCEPT 164M packets, 10G bytes)                                                                                                     
 pkts bytes target     prot opt in     out     source               destination                                                                              
  20M   14G REDIRECT   udp  --  *      *       0.0.0.0/0            0.0.0.0/0            udp dpt:514 redir ports 1514                                                                              
                                                                                                                                                             
Chain INPUT (policy ACCEPT 183M packets, 24G bytes)                                                                                                          
 pkts bytes target     prot opt in     out     source               destination                                                                              
                                                                                                                                                           
Chain OUTPUT (policy ACCEPT 60M packets, 3616M bytes)                                                                                                        
 pkts bytes target     prot opt in     out     source               destination                                                                              
                                                                                                                                                             
Chain POSTROUTING (policy ACCEPT 60M packets, 3616M bytes)                                                                                                   
 pkts bytes target     prot opt in     out     source               destination  

对做好端口转发机器端口扫描:

nmap -vv 10.111.10.11 -sU -p 1514,514

PORT     STATE         SERVICE       REASON                                                                                                                  
514/udp  open|filtered syslog        no-response                                                                                                             
1514/udp open|filtered fujitsu-dtcns no-response                                                                                                             
                                                                                                                                                      
Read data files from: /usr/bin/../share/nmap                                                                                                                 
Nmap done: 1 IP address (1 host up) scanned in 1.58 seconds                                                                                                  
           Raw packets sent: 8 (264B) | Rcvd: 1 (40B)  

同理,配置1443端口转发:

iptables -t nat -A PREROUTING -p tcp --dport 443 -j REDIRECT --to-port 1443

iptables -t nat -L -n -v 


http://www.kler.cn/a/459533.html

相关文章:

  • Navicat 17 for Mac 数据库管理软件
  • Java中如何实现线程安全的单例模式?
  • 探索AI在地质科研绘图中的应用:ChatGPT与Midjourney绘图流程与效果对比
  • DeepSeek v3为何爆火?如何用其集成Milvus搭建RAG?
  • vip与haproxy构建nginx高可用集群传递客户端真实ip
  • STM32-笔记32-ESP8266作为服务端
  • 前端Python应用指南(四)Django实战:创建一个简单的博客系统
  • Java的SpringMVC
  • 嵌入式硬件杂谈(八)电源的“纹波”到底是什么?
  • Linux 信号集与信号掩码
  • uniapp小程序使用rich-text富文本图片溢出问题
  • ZYNQ7000双核AMP文档解读
  • 爬虫的工作原理
  • 百度热力图数据处理流程Arcgis PRO篇,Arcgis,QGIS见链接其他文章
  • 互联网全景消息(8)之RabbitMQ进阶介绍
  • 【机器学习】概述
  • 【C++11】类型分类、引用折叠、完美转发
  • 【数据库初阶】Linux中表的基础操作
  • 【Redis】集群配置(主从复制 哨兵搭建)
  • JPA查询部分字段的最佳实践
  • Python 中的 with open:文件操作的最佳实践
  • 发布远程组件vue2+Webpack和vue3+vite
  • 面试场景题系列:设计云盘系统
  • jmeter设置tps、响应时间监测时间间隔
  • DigitalOcean Kubernetes现已支持VPC natvie集群
  • 【深度学习】Pytorch框架介绍