www.centos.org Forum Index CentOS 6 - General Support SSH port will not change.
|
Bottom Previous Topic Next Topic |
| |
|
|
|---|
| Poster | Thread |
|---|
|
Re: SSH port will not change. | #2 |
|
|---|---|---|---|
|
Peeking in the Member Window
![]()
Joined: 2012/3/27
From Dhaka, Bangladesh
Posts: 16
|
Check out the output of the following command
Check whether your service is listening to the ssh port i.e. 1879. If your server is in fact listening, check whether your firewall is blocking the connection with |
||
Posted on: 2012/5/28 3:06
|
|||
|
Re: SSH port will not change. | #3 |
|
|---|---|---|---|
|
Peeking in the Member Window
![]()
Joined: 2011/11/20
From
Posts: 16
|
This is what I get.
s And this Still can not seem to figure out why it is not changing. |
||
Posted on: 2012/5/29 2:41
|
|||
|
Re: SSH port will not change. | #4 |
|
|---|---|---|---|
|
Professional Board Member
![]()
Joined: 2006/12/30
From Colorado, USA
Posts: 455
|
Did your restart sshd after editing the config file? |
||
Posted on: 2012/5/29 5:02
|
|||
|
Re: SSH port will not change. | #5 |
|
|---|---|---|---|
|
Peeking in the Member Window
![]()
Joined: 2011/11/20
From
Posts: 16
|
I did ... I changed it back to 22 since it was not working. Let me try again.
|
||
Posted on: 2012/6/2 0:05
|
|||
|
Re: SSH port will not change. | #6 |
|
|---|---|---|---|
|
Newbie
![]()
Joined: 2012/7/12
From
Posts: 2
|
Hi,
I got same problem, installing a new DELL R-310 server, default ssh port 22 works fine. when changed to 486, after service sshd restart, I cannot see port 486 is there listening. When changed to port 1486, netstat can see it is listening but cannot connect it. I checked IPTABLES no special access list there. Afterwards I need to put it back to port 22 and everything is ok. not sure what is the problem. |
||
Posted on: 2012/7/12 23:00
|
|||
|
Re: SSH port will not change. | #7 |
|
|---|---|---|---|
|
Newbie
![]()
Joined: 2012/7/4
From
Posts: 6
|
All that much that needs done here edit /etc/ssh/sshd_config adding the 'Port' variable.
In CentOS 6 sshd_config line 13 is the Port variable, by default it is commented out and if so SSH runs on the default of port 22. To change it just un-comment the line and edit the port number such as this: was: # Port 22 to: Port 7777 Then save and restart SSHd with 'server sshd restart' Then a quick 'netstat -ntpl' will show it listening on the new port: # netstat -ntpl Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 18144/varnishd tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1007/master tcp 0 0 0.0.0.0:7777 0.0.0.0:* LISTEN 5977/sshd tcp 0 0 127.0.0.1:6082 0.0.0.0:* LISTEN 18142/varnishd tcp 0 0 :::80 :::* LISTEN 18144/varnishd tcp 0 0 :::8080 :::* LISTEN 18269/httpd tcp 0 0 ::1:25 :::* LISTEN 1007/master tcp 0 0 :::443 :::* LISTEN 18269/httpd tcp 0 0 :::7777 :::* LISTEN 5977/sshd Next you do have to remember to make the firewall changes. I recommend going into /etc/sysconfig/iptables and changing it there vice trying to do new command line rules, but whatever works best for you. No-Mad |
||
Posted on: 2012/7/12 23:26
|
|||
|
Re: SSH port will not change. | #8 |
|
|---|---|---|---|
|
Moderator
![]()
Joined: 2007/10/22
From ~/Earth/UK/England/Suffolk
Posts: 9138
|
What does the following, executed as root, return?
|
||
Posted on: 2012/7/12 23:30
|
|||
|
Re: SSH port will not change. | #9 |
|
|---|---|---|---|
|
Peeking in the Member Window
![]()
Joined: 2009/7/17
From
Posts: 16
|
Quote:
If you have selinux enabled you may need to do this too: # semanage port -a -t sshd_port_t -p tcp 1879 |
||
Posted on: 2012/7/13 3:00
|
|||
|
Re: SSH port will not change. | #10 |
|
|---|---|---|---|
|
Newbie
![]()
Joined: 2012/7/12
From
Posts: 2
|
I found my problem is exactly like the old post:
https://www.centos.org/modules/newbb/print.php?form=1&topic_id=33750&forum=38&order=ASC&start=0 no matter what I did, just port 22 is ok /etc/ssh/sshd_config is fine, I opened port 3022 with port 22, even I tried no port 22 it is same. believe it, I restart and reload it after change. I setup the selinux semanage to allow port 3022 ( other ports that showed are what I tried before) [root@localhost ssh]# semanage port -l | grep ssh ssh_port_t tcp 3022, 1486, 486, 22 port 3022 is listening too: [root@localhost ssh]# netstat -ntpl | grep ssh tcp 0 0 0.0.0.0:3022 0.0.0.0:* LISTEN 10202/sshd tcp 0 0 :::3022 :::* LISTEN 10202/sshd iptables I open port as well: [root@localhost ssh]# iptables -vnL Chain INPUT (policy ACCEPT 0 packets, 0 bytes) pkts bytes target prot opt in out source destination 2482 235K ACCEPT all -- * * 0.0.0.0/0 0.0.0.0/0 state RELATED,ESTABLISHED 0 0 ACCEPT icmp -- * * 0.0.0.0/0 0.0.0.0/0 0 0 ACCEPT all -- lo * 0.0.0.0/0 0.0.0.0/0 7 524 ACCEPT tcp -- * * 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:22 4686 539K REJECT all -- * * 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibited 0 0 ACCEPT tcp -- * * 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:3022 Chain FORWARD (policy ACCEPT 0 packets, 0 bytes) pkts bytes target prot opt in out source destination 0 0 REJECT all -- * * 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibited Chain OUTPUT (policy ACCEPT 1955 packets, 275K bytes) pkts bytes target prot opt in out source destination ssh -vv 172.16.10.70 -p 3022 OpenSSH_4.2p1, OpenSSL 0.9.7f 22 Mar 2005 debug1: Reading configuration data /etc/ssh/ssh_config debug1: Applying options for * debug2: ssh_connect: needpriv 0 debug1: Connecting to 172.16.10.70 [172.16.10.70] port 3022. debug1: connect to address 172.16.10.70 port 3022: No route to host ssh: connect to host 172.16.10.70 port 3022: No route to host |
||
Posted on: 2012/7/13 14:12
|
|||
|
Re: SSH port will not change. | #11 |
|
|---|---|---|---|
|
Moderator
![]()
Joined: 2006/12/13
From Tidewater, Virginia, North America
Posts: 18773
|
Looks like a routing problem, not a port problem. If more help is needed then please provide more information about your system by running "./getinfo.sh network" and showing us the output file.
|
||
|
_________________
Phil Recommended reading: FAQ & Readme first ; Search hint: google "your topic site:centos.org"; Smart Questions |
|||
Posted on: 2012/7/15 13:50
|
|||
|
Re: SSH port will not change. | #12 |
|
|---|---|---|---|
|
Peeking in the Member Window
![]()
Joined: 2011/11/20
From
Posts: 16
|
I got this result from running getinfo.sh
Information for networking problems. |
||
Posted on: 2012/7/20 3:24
|
|||
|
Re: SSH port will not change. | #13 |
|
|---|---|---|---|
|
Peeking in the Member Window
![]()
Joined: 2011/11/20
From
Posts: 16
|
Anyone have any idea to why this is the change of port is not working? I am still lost.
Thanks |
||
Posted on: 2012/7/28 4:01
|
|||
|
Re: SSH port will not change. | #14 |
|
|---|---|---|---|
|
Moderator
![]()
Joined: 2009/9/24
From Brighton, UK
Posts: 6368
|
You have added the iptables rule to allow port 3022 to the end of the chain, after the existing final one that rejects everything - this means it's never reached because it rejects everything before it reaches it.
|
||
|
_________________
Linux/VoIP Systems Administrator |
|||
Posted on: 2012/7/28 11:01
|
|||
|
Re: SSH port will not change. | #15 |
|
|---|---|---|---|
|
Peeking in the Member Window
![]()
Joined: 2011/11/20
From
Posts: 16
|
Quote:
Really? This is a clean install. I have done nothing but tried to change the SSH port ... How can I fix this? The only thing which I have installed is BFD ... but I checked that and it does not seem to be blocking any ports. Thanks |
||
Posted on: 2012/7/28 20:18
|
|||
|
Re: SSH port will not change. | #16 |
|
|---|---|---|---|
|
Moderator
![]()
Joined: 2009/9/24
From Brighton, UK
Posts: 6368
|
The default INPUT iptables chain in CentOS 6 has a final rule which rejects everything that hasn't matched a previous ALLOW rule. If you use `iptables -A INPUT ...` then this will append a rule to the end of the INPUT chain after the one that rejects everything and will never be reached. Check by running `service iptables save` then look in /etc/sysconfig/iptables for a rule that looks like
I bet your new rule is listed after that one. Move it up above the REJECT one, save the file and run `service iptables restart` and it will take effect (existing connections may be dropped when you run the restart). The solution to this next time is to insert your new rule at a specific position in the chain by giving it a line number, e.g. to insert the rule so it's on line 3 of the ruleset use |
||
|
_________________
Linux/VoIP Systems Administrator |
|||
Posted on: 2012/7/28 20:27
|
|||
|
Re: SSH port will not change. | #17 |
|
|---|---|---|---|
|
Peeking in the Member Window
![]()
Joined: 2011/11/20
From
Posts: 16
|
"state NEW -m tcp --dport 22 -j ACCEPT" I am trying to change the port to 1992 ... shouldn't the "22" change to 1992 by it self? Thanks |
||
Posted on: 2012/7/28 21:17
|
|||
|
Re: SSH port will not change. | #18 |
|
|---|---|---|---|
|
Professional Board Member
![]()
Joined: 2006/12/30
From Colorado, USA
Posts: 455
|
Quote:
No. Edit the file, change the port to the correct number, save, then restart IPTABLES. |
||
Posted on: 2012/7/28 22:05
|
|||
|
Re: SSH port will not change. | #19 |
|
|---|---|---|---|
|
Peeking in the Member Window
![]()
Joined: 2011/11/20
From
Posts: 16
|
I did that but it keeps on changing it back to 22 ... not sure what is happening.
|
||
Posted on: 2012/7/28 23:18
|
|||
|
Re: SSH port will not change. | #20 |
|
|---|---|---|---|
|
Moderator
![]()
Joined: 2009/9/24
From Brighton, UK
Posts: 6368
|
If you have
IPTABLES_SAVE_ON_RESTART="yes" set in /etc/sysconfig/iptables-config and edit the file and do a restart then it'll be overwritten during the restart. Either stop the service, edit the file, start it again or learn how to use `iptables -I ` (the latter would be my preferred solution since it doesn't leave you with a window where the firewall is stopped). |
||
|
_________________
Linux/VoIP Systems Administrator |
|||
Posted on: 2012/7/28 23:39
|
|||
Top Previous Topic Next Topic |
|



Topic options
Print Topic
Threaded
Newest First
youknowme






You cannot start a new topic.
You can view topic.