当前位置:首页 > Contributors > 正文内容

适用于debian和centos的端口转发 好用的菜鸟级教程

admin1年前 (2022-08-14)Contributors555

什么是端口转发?为什么要转发?

准确来讲叫流量转发,因为流量是基于端口的,所以一般称为端口转发。
比如电信到伯力很差,我买了个上海联通鸡做转发,那么就是
电信->联通:1200->伯力:4900,那么我访问联通的1200端口,等于访问伯力的4900端口
转发还可以用于公网frp,反代网站等用途

用什么转发?

推荐iptables或者firewalld,都是内核级别的转发,性能损耗极少。
如果用gost/brook等第三方工具转发,流量大或者连接数过多的时候cpu和负载压力变大,对于nat小鸡特别不友好。

正文开始

基于firewalld转发(适用于centos7)

我记得debian也能安装firewalld,能安装的话一样可以用他来转发。
以下命令都在中转机(上海联通)执行

#先停止iptables

systemctl stop iptables systemctl disable iptables

#安装,开机启动

yum install firewalld systemctl start  firewalldsystemctl enable firewalld.service

 

#状态:显示绿色active说明服务运行正常

systemctl status firewalld

#开启内核转发,然后重启

echo 1 > /proc/sys/net/ipv4/ip_forwardsysctl -preboot

到这里安装完成,
然后直接编辑vi /etc/firewalld/zones/public.xml 文件,这个是firewalld配置文件
把下面的配置粘贴进去

 

<?xml version="1.0" encoding="utf-8"?><zone><short>Public</short><description>For use in public areas. You do not trust the other computers on networks to not harm your computer. Only selected incoming connections are accepted.</description><service name="ssh"/><service name="dhcpv6-client"/><port protocol="tcp" port="10-65000"/><port protocol="udp" port="10-65000"/><masquerade/><forward-port to-addr="远程ip" to-port="远程端口" protocol="tcp" port="本地端口"/><forward-port to-addr="远程ip" to-port="远程端口" protocol="udp" port="本地端口"/></zone>

 

 

#重启防火墙就生效了

systemctl restart firewalld.service

是不是比百度出来的一大堆命令要简单,
每次修改 public.xml 要重启防火墙才会生效

用站长工具扫描一下上海联通ip的1200端口,开了说明转发成功

 

此时访问 海联通ip:1200端口,等于访问伯力:4900端口
也就是把你的v2 sr的客户端,ip和端口改为 海联通ip和1200,就可以了!

基于iptables转发(适用于C7,D8)

#先安装iptables,debian换成 apt-get install

yum install -y iptables
yum install -y iptables-services

#开机启动

systemctl start iptables
systemctl enable iptables

#查看服务状态,显示绿色active就可以了

service iptables status

#清空所有防火墙规则,避免因端口没开造成影响

iptables -Fiptables -X

#开启内核转发,重启

echo -e "net.ipv4.ip_forward=1" >> /etc/sysctl.confsysctl -preboot

到这里安装完成,然后用知名的转发脚本,按提示转发。
这个脚本是帮你一键执行iptables命令,还是调用iptables,非第三方转发软件,支持ddns,感谢arloor
https://github.com/arloor/iptablesUtils

wget --no-check-certificate -qO natcfg.sh https://raw.githubusercontent.com/arloor/iptablesUtils/master/natcfg.sh && bash natcfg.sh

 

转载来自:https://jkboy.com/archives/5114.html

扫描二维码推送至手机访问。

版权声明:本文由博赚恋吧资源站发布,如需转载请注明出处。

本文链接:https://432l.com/post/9743.html

分享给朋友:

相关文章

Free-space - 500M/可绑米/cPanel面板/免费PHP空间

Free-space为大家免费提供采用cPanel管理面板的免费虚拟主机,FTP、WEB方式上传管理文件,支持PHP5、CGI(Perl),提供免费二级域名。有两种型号免费PHP空间:1、200M免费空间,2G月流量,1个MySQL数据库,可绑定1个自己的域名或使用Free-space免费提供的二级域名(申请的时候选择,空间开通后无法改变),无广告;2、500M免费空间,10G月流量,2个MySQ...

lunarhosting1提供5G可绑域名免费PHP空间

lunarhosting1提供5G,流量每月40G可绑绑域名PHP/MYSQL/CP/FTP免费空间 Plan 1 Space 5 GB Brandwith 40 GB...

007GB提供700MB,流量7GB的可绑米PHP免费空间

Visit: 007Gb http://www.007gb.com/ (Click above to go to this free web site hosting service.) Interests:...

恋吧推荐—Atgig提供10G可绑米免费PHP空间(访问速度相当的快)

      Atgig免费空间,空间大小10G,每月100G流量限制,采用DirectAdmin后台管理,支持FTP,PHP。The Ultimate Free Hosting Plan 10GB Diskspace FTP access 100GB Bandwidth Easy control panel Ba...

stonerocket.提供1G大小25G流量的Cpanel面板免费PHP空间

Free Cpanel PHP/MySQL Web HostingScripts & Usage | Freehosting | 免费空间 | 2009.05.26 http://stonerocket.net提供1G空间25G流量的免费Cpanel空间。We Have been offering reliable free web hosting since 2005这是一家从2005年就开始提...

HOST1PLUS提供的免费(公益)网站放置(托管)服务

记得几个月前HOST1PLUS提供免费的500M空间,可是不久后都关了,刚刚站长在邮箱打开发现HOST1PLUS发来的邮件。就随手打开看了看,居然都做有中文站了啊,不无偿提供免费空间了,然而我还是看到了HOST1PLUS提供的免费(公益)网站放置(托管)服务计划!免费(公益)网站放置(托管) 您是否想过发展原创项目为社会谋求福利,而苦于手中没有优质网站托管资源? 如果满足以下条件,Host1Plu...

评论列表

admin
admin
10个月前 (12-13)

wget -N --no-check-certificate https://raw.githubusercontent.com/hugoyue/doubi/master/iptables-pf.sh && chmod +x iptables-pf.sh && bash iptables-pf.sh

admin
admin
10个月前 (12-13)

https://www.pianyun.com/news/content/178.html

发表评论

访客

◎欢迎参与讨论,请在这里发表您的看法和观点。