this post was submitted on 16 Feb 2025
20 points (100.0% liked)
Linux
50449 readers
622 users here now
From Wikipedia, the free encyclopedia
Linux is a family of open source Unix-like operating systems based on the Linux kernel, an operating system kernel first released on September 17, 1991 by Linus Torvalds. Linux is typically packaged in a Linux distribution (or distro for short).
Distributions include the Linux kernel and supporting system software and libraries, many of which are provided by the GNU Project. Many Linux distributions use the word "Linux" in their name, but the Free Software Foundation uses the name GNU/Linux to emphasize the importance of GNU software, causing some controversy.
Rules
- Posts must be relevant to operating systems running the Linux kernel. GNU/Linux or otherwise.
- No misinformation
- No NSFW content
- No hate speech, bigotry, etc
Related Communities
Community icon by Alpár-Etele Méder, licensed under CC BY 3.0
founded 5 years ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
Your hook has
/sbin/iptables -t nat -I PREROUTING -p tcp --dport $HOST_PORT -j DNAT --to $GUEST_IP:$GUEST_PORT
But I'd didn't think that "--to" was a flag for DNAT, I thought it was "--to-destination"
If you 'iptables -nvL' and 'iptables -t nat -nvL' do you see both your DNAT and forwarding rules (although if the default is ACCEPT and you don't have other rules, the FORWARD one isn't needed), and do you see the packet count for the rules increase?
From the
iptables
manpage:This seems to do something, but the port still appears as closed.
iptables -nvL
returns:I've omitted some listings that were labelled as docker.
iptables -t nat -nvL
returns:I've also omitted some listings that were labelled as docker.
After running the
ssh
command, the bytes seem to increase. After 1 ssh attempt:After another ssh attempt:
For general awareness, not all flags can match all parts of an iptables command; the part you included there with "--to offset" is only valid with the string module, and not the DNAT action. That said after playing around with it a little, iptables actually does short flag matching, so 'DNAT --to 1.2.3.4' 'DNAT --to-d 1.2.3.4' and 'DNAT --to-destination' are all equivalent, so not the source of your issue.
I am having trouble following the IP scheme, though. Is your Alma guest 192.168.101.4, or is that the host IP? If it's Alma's and you are attempting to ssh from that IP to the host with that iptables rule, what should happen is that DNAT would then redirect that connection back to Alma. If the guest doesn't have a :22 listener, you'd get a connection refused from itself.
192.168.101.4
is the alma guest. It's got port 22 open and I can ssh into it from the host computer.iptables -nvL on Alma returns:
I believe this means it automatically accepts connections.
IMO this makes it unlikely that the guest is the issue.
Sorry, I was looking more specifically at that DNAT rule
That rule exists in the host 192.168.86.73, correct? And from the guest, 192.168.101.4 you are attempting to ssh into 192.168.86.73:2222?
It might not be your issue (or only issue), but that DNAT rule says that if a connection comes in on port 2222, instead send it to 192.168.101.4:22. So 192.168.101.4->192.168.86.73:2222->192.168.101.4:22. I would have thought you'd want it to be a DNAT to 192.168.86.73, functionally doing port bending, so it goes 192.168.101.4->192.168.86.73:2222->192.168.86.73:22.
That doesn't explain the connection refused, though, based on what you've said; there's some fringe possibilities, but I wouldn't expect for your setup if you hadn't said (like your ~/.ssh/ssh_config defining an alternate ssh port for your guest OS than 22). It's somewhat annoying, but it might be worthwhile to do a packet capture on both ends and follow exactly where the packet is going. So a
tcpdump -v -Nnn tcp port 22 or tcp port 2222
I ended up just installing Alma Linux again. Thank you very much for your help.
yes, the host is 192.168.86.73 and it has that dnat rule.
Assuming you meant from the host, I am sshing directly to 192.168.101.4 instead of to 192.168.86.73:2222.
The third paragraph doesn't make sense to me. I am using port 22 on my host(192.168.86.73) for it's own ssh.
tcpdump
returns this when I ssh to port 2222: