[Linux]ubuntu開放server的指定埠

luck-cheng發表於2017-06-20

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的指定埠

相關文章