[Linux]ubuntu开放server的指定端口

本文详细介绍了如何在Ubuntu系统中使用iptables命令打开指定端口,包括广播端口5600和TCP端口8000的方法,并展示了如何设置防火墙规则允许特定端口的数据包通过。此外,还提供了使用nc命令创建简单客户端/服务器模型的例子。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

refs:

http://askubuntu.com/questions/293356/how-to-open-a-particular-port-in-ubuntu

Run this on the commandline; it should solve issue: sudo iptables -A INPUT -m conntrack –ctstate NEW,RELATED,ESTABLISHED -j ACCEPT

To do a specific port:

sudo iptables -A INPUT -p <tcp OR udp> <--dport OR --sport> <port> -j ACCEPT

INPUT is the chain for incoming traffic. -p is protocol (either tcp or udp –dport or –sportspecify allowing for destination or source port. -j is “jump” and its where you ACCEPT, REJECT, orDROP the packet(s)

所以,开放5600端口接收广播,结果:

sudo iptables -A INPUT -p udp -d 0/0 -s 0/0 --dport 5600 -j ACCEPT

开放8000端口接收tcp,结果:

sudo iptables -A INPUT -p tcp -d 0/0 -s 0/0 --dport  8000 -j ACCEPT

设置防火墙的规则,允许5600端口进入

 sudo ufw allow  5600
 sudo ufw allow  8000

查看状态:

sudo netstat -ntlup

nc 用法:

refs:

http://manpages.ubuntu.com/manpages/hardy/man1/nc_openbsd.1.html

CLIENT/SERVER MODEL

 It is quite simple to build a very basic client/server model using nc.
 On one console, start nc listening on a specific port for a connection.
 For example:

       $ nc -l 1234

 nc is now listening on port 1234 for a connection.  On a second console
 (or a second machine), connect to the machine and port being listened on:

       $ nc 127.0.0.1 1234

开放ubuntu server的指定端口

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值