Using netcat with -p option [closed] - linux

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
I used netcat in the following way
nc -l 3333 //for server
nc 127.0.0.1 3333 // for client
With this I am able to use it as a two way chatting system.
My question is, then why is there another option
-p ( -p source_port Specifies the source port nc should use, subject to privilege restrictions and availability.)
It works with -p option too. What is the difference between the two?

A TCP connection consists of two TCP endpoints, each consisting of an IP address and a TCP port. The client usually chooses a random port, although you can force netstat to use a given port using the -p option.
Try:
adi#laps:~$ nc -l 3333 -p 4444
nc: cannot use -p and -l
adi#laps:~$ nc -l 3333 &
[1] 6025
adi#laps:~$ nc localhost 3333 -p 3333
nc: bind failed: Address already in use

Related

linux iptables redirect outgoing traffic to local port [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 8 years ago.
Improve this question
I want redirect all outgoing traffic with port 8080 to local port 8080
for example i create server with this command nc -l -p 8080 and i want when use this command nc 1.2.3.4 8080 , nc redirect and connect to 127.0.0.1:8080
i try with this command:
iptables -t nat -A POSTROUTING -p tcp --dport 80 -o eth0 -j SNAT --to-source IP
but not worked!
how to do it?
Local originated traffic isn't passing through nat/POSTROUTING chain. You should add rule like this:
iptables -t nat -A OUTPUT -p tcp --dport 8080 -j DNAT --to-destination 127.0.0.1:8080
Additional info:
http://upload.wikimedia.org/wikipedia/commons/3/37/Netfilter-packet-flow.svg
http://www.linuxtopia.org/Linux_Firewall_iptables/index.html Chapter 4.

Open port 443 by adding a rule in iptables (Ubuntu) [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 9 years ago.
Improve this question
Im new to ubuntu and using ubuntu server 12.04.
When I run nmap localhost I get the following output :
Not shown: 997 closed ports
PORT STATE SERVICE
22/tcp open ssh
80/tcp open http
3306/tcp open mysql
This means that port 443(https) is closed. I want to open it.
So I did the following :
I ran the command
sudo iptables -A INPUT -p tcp --dport 443 -j ACCEPT
And to persist the changes I saved the file using sudo sh -c "iptables-save > /etc/iptables.rules"
and then I added the following lines to etc/network/interfaces :
pre-up iptables-restore < /etc/iptables.rules
post-down iptables-save > /etc/iptables.rules
After rebooting my system I ran sudo iptables -L and the line
Chain INPUT (policy ACCEPT)
target prot opt source destination
ACCEPT tcp -- anywhere anywhere tcp dpt:https
was visible.
However now when I run nmap localhost I still dont see 443 as open.
Please help!
I bet you have nothing listening to port 443 on your host. Try this: in one terminal run sudo nc -lk 443 and then run your nmap localhost. This may not have anything to do with an iptables firewall rule.

iptables to drop input connections to postgres [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
For testing, I need to drop all input connections to postgres db running on port 5432 on localhost. I set an iptables rule :
iptables -A INPUT -s 127.0.0.1 -p tcp --dport 5432 -j DROP
But I am able to do read/write operations to the db. I used dbvisualizer as well as the product to test. What am I missing?
Thanks in advance.
The target DROP will just drop the packet, no further processing or forwarding.
try this:
iptables -t nat -A PREROUTING -p tcp -j REDIRECT --to-ports 5432
I am not sure if this is the right method but rule
iptables -A OUTPUT -p tcp --dport 5432 -j REJECT
worked as expected.
Did your server listen on localhost or ethernet nic network ip address?

Redirect all outgoing traffic on port 80 to a different IP on the same server [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
I have multiple IP addresses on the same server and I would like to redirect all outgoing traffic on port 80 to a different IP on the same server just no to use always main IP.
Currently I'm using this:
/sbin/iptables -t nat -A POSTROUTING -o eth0 -j SNAT --to-source IP;
and it works well, but it redirects everything and when I make backups over SSH backup it's failing.
System: CentOS 5.8 64-bit
This worked:
iptables -t nat -A POSTROUTING -p tcp --dport 80 -o eth0 -j SNAT --to-source IP

Port mirroring on Linux [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
I have Kippo running on my VPS, and I can't get it to run under port 1024 due to restrictions in Linux not allowing normal accounts to use ports under 1024. If I try, it gives an error with some Python gibberish about not being able to listen on a port under 1024.
I'd rather not run Kippo run as root just in case some how they get out of the Kippo enviroment.
So what I'm looking at doing is using IPTables to "Mirror" all traffic going to port 2222 on 22 so that a "bot" can see SSH running on port 22 and do its thing.
Is that feasible? If so, how?
Use a DNAT rule:
iptables -t nat -A PREROUTING -m tcp -p tcp --dport 22 -j REDIRECT --to-port 2222
You may want to lock down further with specific IP address filters

Resources