G
G
glebrain2017-07-23 00:08:20
Windows
glebrain, 2017-07-23 00:08:20

How to connect from Windows to centos on port 5555?

Hello! help me figure it out...
I have:
[1] Home host on Centos, IP: 192.168.1.5 (here the socket server sits at 127.0.0.1:5555)
host external IP: xxxx
[2] Home server on Windows, IP: 192.168.1.6 (there is a program on it, it polls 192.168.1.5:5555)
[1] and [2] are in the local network:

cmd>ping 192.168.1.5
...
Статистика Ping для 192.168.1.5: Пакетов: отправлено = 4, получено = 4, потеряно = 0  (0% потерь)
Приблизительное время приема-передачи в мс: Минимальное = 0мсек, Максимальное = 1 мсек, Среднее = 0 мсек

I need the program [2] to connect to the socket server [1] .
After digging in the internet, I realized that I needed to change iptables, I tried the options:
iptables -A INPUT -p tcp -m tcp --dport 5555 -m state --state NEW -j ACCEPT
iptables -A INPUT -i enp2s0 -p tcp -m tcp --dport 5555 -j ACCEPT
iptables -A INPUT -i enp2s0 -p tcp -m conntrack --ctstate NEW -m multiport --dports 5554:5556 -j ACCEPT
iptables -A INPUT -p tcp -m tcp --dport 5555 -m state --state NEW -j ACCEPT
iptables -A INPUT -s 192.168.1.6/32 -p tcp -m conntrack --ctstate NEW -m multiport --dports 5554:5556 -j ACCEPT
service iptables save
/bin/systemctl restart  iptables.service

The commands above, I tried to write one at a time and all at once and in a different order, the result is always the same:
[1]:
// сокетсервер забинден на localhost:5555 
[[email protected] ~]# fuser -vn tcp 5555
                     ПОЛЬЗ-ЛЬ    PID ДОСТУП КОМАНДА
5555/tcp:       chel   8336 F.... php    

// прослушивание есть
[[email protected] ~]# netstat -na | grep 555
tcp        0      0 127.0.0.1:5555          0.0.0.0:*               LISTEN

[2]:
cmd> telnet
telnet> o 192.168.1.5 5555
Подключение к 192.168.1.5...Не удалось открыть подключение к этому узлу, на порт
 5555: Сбой подключения
telnet> o x.x.x.x 5555
Подключение к x.x.x.x...Не удалось открыть подключение к этому узлу, на порт
 5555: Сбой подключения

I tried to hang the socket server on 127.0.0.1:5555 or on 192.168.1.5:5555, it says connected, but the result is the same ...
after digging further, I understand that I need to somehow allow listening on 192.168.1.5 on port 5555, I came across article: help.ubuntu.ru/wiki/iptables, subtracted from it about PREROUTING, tried the option:
iptables -t nat -A PREROUTING -p tcp -m tcp -d 192.168.1.6 --dport 5555 -j DNAT --to-destination 192.168.1.5
iptables -t nat -A POSTROUTING -p tcp -m tcp -s 192.168.1.5 --sport 5555 -j SNAT --to-source 192.168.1.6:5555

doesn't work... my head is boiling, I don't understand how to make it work... Please help me figure it out (:

Answer the question

In order to leave comments, you need to log in

[[+comments_count]] answer(s)
V
vreitech, 2017-07-23
@fzfx

what does the "sestatus" command run with superuser privileges say?

S
Spheniscus, 2017-07-23
@Spheniscus

If Centos version 7+, then it is easier to forward ports like this:

firewall-cmd --add-port=5555/tcp --permanent
firewall-cmd --reload

After that try to connect

G
glebrain, 2017-07-23
@glebrain

Spheniscus, it turns out that firewalld is a replacement for Iptables and fail2ban (based on the article https://xakep.ru/2017/02/15/firewalld/ )?
Unfortunately, there are sites on the host and iptables contains 93 lines, I'm afraid that I won't be able to configure firewalld correctly :)
Spheniscus, thanks for the information on how one of the solutions will work for the future.
But still I would like to know how to configure iptables?
2 local servers seem to be complicated, connected via a router, the port does not go from Windows to Centos (although they see each other on the network), or maybe vice versa?
from Centos to Windows on port 5555 can it be easier?

K
krosh, 2017-07-24
@krosh

iptables -I INPUT -s 192.168.1.0/24 -m tcp -p tcp --dport 5555 -j ACCEPT
Note that there is an append to the front of the list (-I) option, and you used the append to the end (-A) option list of rules. I saw a list in CentOS in which the last rule was REJECT, i.e. everything below did not work. Check for yourself.
It is good to show all the rules at once in such questions:
iptables-save

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question