Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


assign port number

Posted on 1999-07-23
Medium Priority
Last Modified: 2010-04-20
if i have root privilege, can i assign a port number below 1000 for my server side socket program.  i am not sure how to do it, do i have to modify the /etc/services files or just execute my server side program as a root, so i am able to "bind" a socket with port number below 1000. any input will be greatly appreicated.

Question by:vzhang
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2

Expert Comment

ID: 1635726
read the manual pages, buddy!

man services includes the first lines:
       services is a plain ASCII file providing a mapping between
       friendly textual names for internet  services,  and  their
       underlying assigned port numbers and protocol types. Every
       networking program should look into this file to  get  the
       port number (and protocol) for its service.  The C library
       routines   getservent(3),   getservbyname(3),   getservby­
       port(3), setservent(3), and endservent(3) support querying
       this file from programs.

so: you may bind to any port you'd like as long as you are root, but you should use services as a "configuration" file, where you take the right port from....

Author Comment

ID: 1635727
thanks gunny for your input!  what happen if i bind a port which is used by other services like "telnet". am i going to have a conflict if i start to run my program. if i am not the root, what is samllest port number am allowed to bind. i run into trouble couple times with binding the socket to the port when i executed the program as user.  it complains that  port is in service.  i just want to choose a port number that will alway allowed me to bind to that port.  

Accepted Solution

gunny051499 earned 90 total points
ID: 1635728
i'm not sure wheater this is defined or not. actualy if you use /etc/services a port conflict should never happen. also it is quite clear that you are going to run into trouble, when installing two services on the same port.

man services, 3th paragraph:
       Port numbers below 1024 (so-called 'low  numbered'  ports)
       can  only  be  bound  to by root (see bind(2), tcp(7), and
       udp(7).)  This is so that clients connecting to  low  num­
       bered ports can trust that the service running on the port
       is the standard implementation, and not  a  rogue  service
       run  by  a  user  of the machine.  Well-known port numbers
       specified by the IANA are normally located  in  this  root
       only space.

if you want to choose a "safe" port (this is an assumption, since as long as your port is not a standard, you could always run into confilct on some other machine) have a look at your existing /etc/services and choose something like port 13193, i'm quite sure not much people are using such things :)

also i realy recommand you to READ the services manualpage!!

Author Comment

ID: 1635729
thanks again gunny, do you know why when i termined my server socket program and try to run it again, it give me the message "bind: Address already in use ", that doesn't make any sense, so each time i terminated my program i have to change the port number and recompile the programs again in order to execute it. any input will be greatly appreciated.  for now, i think i will just change the /etc/services file and choose a port below 1024 and run as root.

Expert Comment

ID: 1635730
'you sure you killed the socket?

Featured Post

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I am a long time windows user and for me it is normal to have spaces in directory and file names. Changing to Linux I found myself frustrated when I moved my windows data over to my new Linux computer. The problem occurs when at the command line.…
Using 'screen' for session sharing, The Simple Edition Step 1: user starts session with command: screen Step 2: other user (logged in with same user account) connects with command: screen -x Done. Both users are connected to the same CLI sessio…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Suggested Courses

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question