Fedora Linux Support Community & Resources Center

Go Back   FedoraForum.org > Fedora 17/18 > Servers & Networking
FedoraForum Search

Forgot Password? Join Us!

Servers & Networking Discuss any Fedora server problems and Networking issues such as dhcp, IP numbers, wlan, modems, etc.

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 12th June 2011, 02:02 AM
Lumpyone Offline
Registered User
 
Join Date: Jun 2011
Posts: 3
linuxfedorafirefox
Changing SSH Port in Firewall

I'm new to Fedora, switching to it from Ubuntu recently because I've heard some good things about Fedora and wanted to give it a try.

I'm attempting to configure SSH to allow me to connect remotely with a different port, in this case, port 2222.

I encountered an error with SELinux when I attempted to change the port in the /etc/ssh/sshd_config file and after some research discovered how I could change that through the terminal with semanage port -a -t ssh_port_t -p tcp 2222. I then verified with semanage port -l | grep ssh

I restarted and when I check with SELinux, the port is added. However, I still am unable to SSH to the machine on port 2222. I'm curious if I've missed something or perhaps have done something wrong.

The only thing I can think I have missed is the Firewall. I check it and under the ssh service, only port 22 is listed. I can't seem to find a way to change that setting in the Firewall. Perhaps that is keeping me from ssh'ing into the machine?

Any and all help is appreciated.
-JW
Reply With Quote
  #2  
Old 12th June 2011, 02:53 AM
smr54 Offline
Registered User
 
Join Date: Jan 2010
Posts: 4,976
linuxchrome
Re: Changing SSH Port in Firewall

something like


iptables -A --state NEW -m tcp -p tcp --dport 2222 -j ACCEPT

should work I think. (Not tested on Fedora)

Then, to save it, if it work

iptables-save > /etc/sysconfig/iptables
Reply With Quote
  #3  
Old 12th June 2011, 04:01 PM
Lumpyone Offline
Registered User
 
Join Date: Jun 2011
Posts: 3
linuxfedorafirefox
Re: Changing SSH Port in Firewall

With that command I get a 'Bad argument 'NEW'
Reply With Quote
  #4  
Old 12th June 2011, 04:42 PM
smr54 Offline
Registered User
 
Join Date: Jan 2010
Posts: 4,976
linuxchrome
Re: Changing SSH Port in Firewall

Hrrm, OK, I was looking at a CentOS install.

Try with

iptables -A -p tcp --dport 2222 -j ACCEPT and see if that works.
Reply With Quote
  #5  
Old 12th June 2011, 05:14 PM
Lumpyone Offline
Registered User
 
Join Date: Jun 2011
Posts: 3
linuxfedorafirefox
Re: Changing SSH Port in Firewall

Again, I was getting a bad argument this time for 'tcp'

Thanks for the help, I decided to try the GUI and looks like I was able to add it there. However, it appears the problem is with SELinux. I either have not done something write with changing its settings or there is more I need to do.

I disabled SELinux and I'm curious if that is a good thing or not. Doing more reading on SELinux to find out how to get this to work, especially with wanting to access the desktop and applications remotely, and even setting the machine up as a proxy.

Thanks again for the assistance
Reply With Quote
  #6  
Old 12th June 2011, 06:03 PM
smr54 Offline
Registered User
 
Join Date: Jan 2010
Posts: 4,976
linuxchrome
Re: Changing SSH Port in Firewall

Well, turns out I didn't help much, but glad you got it working. I'll have to play with the syntax on a Fedora box.

SELinux, if it's a home machine, is probably not necessary and some people disable it. However, it's gotten very easy to use, and I believe there are some good GUI tools, including a troubleshooter I think. Also, there are sometimes messages in /var/log/messages that will have instructions as to how to fix a problem.

It's best to leave it enabled if possible, and there are differing schools of thought about whether it's necessary, especially for a home machine, or not. There's also the option (in /etc/sysconfig/selinux) to set it to permissive (at least in CentOS--the syntax may be slightly different in Fedora) where it will just print a warning instead of enforcing.
Reply With Quote
  #7  
Old 12th June 2011, 06:19 PM
stevea's Avatar
stevea Online
Registered User
 
Join Date: Apr 2006
Location: Ohio, USA
Posts: 8,300
linuxfedorafirefox
Re: Changing SSH Port in Firewall

Disabling SEL is not a great idea.
I'm not the SEL expert but the SEL troubleshooter usually gives good advice.
__________________
None are more hopelessly enslaved than those who falsely believe they are free.
Johann Wolfgang von Goethe
Reply With Quote
  #8  
Old 12th June 2011, 06:24 PM
bodhi.zazen's Avatar
bodhi.zazen Offline
Registered User
 
Join Date: Jul 2006
Location: Montana
Posts: 731
unknownunknown
Re: Changing SSH Port in Firewall

IMO you are better off by far with ssh on the default port and selinux enabled then your current set up with ssh on an alternate port with selinux disabled.

After running ssh servers for many years I leave them on port 22 and use keys (disable password authentication).

If that is not sufficient, then add a "simple" rule(s) to iptables to rate limit new connections.

Code:
iptables -A INPUT -p tcp -m tcp --dport 22 -m tcp -m state --state NEW -m recent --set --name SSH --rsource

iptables -A INPUT -p tcp -m tcp --dport 22 -m recent --update --seconds 600 --hitcount 8 --rttl --name SSH --rsource -j DROP

iptables -A INPUT -p tcp -m tcp --dport 22 -j ACCEPT
Keep in mind, order of your rules matters, so rather then -A you likely will need to use -I (insert) and put them in the correct location in your rule set.

The previous commands that failed were incomplete.

See : http://bodhizazen.net/Tutorials/iptables

or most any online iptables guide for further information.

Note: if you set your hit count too low you will have problems with scp and sftp as each file transfer counts as a new connection. If you find 8 to low , increase it to 10-20 .
__________________
If it is not broken, tweak it... If you break Fedora you get to keep both pieces :p

Last edited by bodhi.zazen; 12th June 2011 at 06:26 PM.
Reply With Quote
  #9  
Old 24th June 2011, 07:42 PM
lightman47 Offline
Registered User
 
Join Date: Apr 2009
Posts: 266
linuxchrome
Re: Changing SSH Port in Firewall

In Firewall, can't you just turn off SSH, then ad your 2222 in "other ports"?
Reply With Quote
Reply

Tags
changing, firewall, port, ssh

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
UPnP firewall port Seeker Using Fedora 1 22nd October 2009 11:08 PM
Firewall/Port Forward hotelunderseige Security and Privacy 3 22nd March 2009 11:09 AM
[Firewall]stealthing used port... LDC Security and Privacy 3 8th April 2008 10:49 PM
Why does my ssh keep dropping after changing its port pushback Servers & Networking 3 10th September 2005 04:12 AM


Current GMT-time: 00:34 (Monday, 20-05-2013)

TopSubscribe to XML RSS for all Threads in all ForumsFedoraForumDotOrg Archive
logo

All trademarks, and forum posts in this site are property of their respective owner(s).
FedoraForum.org is privately owned and is not directly sponsored by the Fedora Project or Red Hat, Inc.

Privacy Policy | Term of Use | Posting Guidelines | Archive | Contact Us | Founding Members

Powered by vBulletin® Copyright ©2000 - 2012, vBulletin Solutions, Inc.

FedoraForum is Powered by RedHat