Configure static IP for Linux OS

Dear Experts,

How do I configure the static IP Address of a linux server?

Is it?

Method 1

Ifconfig eth0 netmask up
Route add Default gw
Echo “nameserver”> /etc/resolv.conf

Method 2

Sudo ifconfig eth0 netmask
Sudo route add Default gw eth0

Are there other methods?

I just want to cover all the possibilities so I won't get stuck if any of the methods do not work.

I also know that only the root can change the IP Address.
Anonymous KHIT EngineerAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Which Linux system?
There are commonly network config tools

Knowing which system you are on can clarify..

Usually during the install, you are promoted for all the information including network.....
Pushpakumara MahagamageVPCommented:
What is the linux flaver I mean Redhat, Debian, FreeBSD etc,

you can edit network file #

you can use the GUI also ----

Route you have to add separately ---- static / persistent
Anonymous KHIT EngineerAuthor Commented:
Sorry it is a Redhat Linux
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

Prabhin MPEngineer-TechOPSCommented:
Anonymous KHIT EngineerAuthor Commented:
I did not know that I have to add broadcast address.
Prabhin MPEngineer-TechOPSCommented:
dont configure broadcast address, configure only IP address , netmask , gateway and DNS.
Pushpakumara MahagamageVPCommented:
Hi Kevin,

What is the perfect method to apply network settings, I mean linux command, edit network file or use GUI.
Pushpakumara MahagamageVPCommented:

I'm asking you. Which method you like to use.
Hi Pushpakumara Mahagamage,

Personally, I prefer using the command line.

Since I am working on clients' servers / machines, I document everything I do as a basic professional requirement.  If I use the command line for everything possible, then it is really easy to document, and also to script a new setup / machine to be exactly the same if I ever need to (just run a script with all the commands).

It is also much easier to look through the script and see if, over time, you can consolidate or remove lines where configuration has changed.

For example, maybe a machine started out with one static IP, and then got a different static IP.  If I ran all the commands on a new setup it would still correctly get the new Static IP (assuming that is what we want), but I could also remove the earlier assignment and reduce the number of lines / commands / clutter.

Hope that helps,


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
See if you have system-config-network-tui
Before running, make sure you have the ip, netmask, and default gateway along with at least one nameserver ip.
David FavorLinux/LXD/WordPress/Hosting SavantCommented:
Probably good to ask if you're doing this on a local system or server which you've leased from a hosting company.

If you've leased a machine from a hosting company, they should provide you with network setup + any alteration is unwise.

So, just to be clear make an update as to what type of machine this is - local machine or hosting company machine.
Anonymous KHIT EngineerAuthor Commented:
It is a client's server but it has a GUI, my colleague saw it. Another issue is that it is also mirroring the database to a secondary server, virtualising it is going to be an issue.
David FavorLinux/LXD/WordPress/Hosting SavantCommented:
I'll ask my question differently. Update your question with where this machine resides physically.

Can you walk to it + touch it or is it deployed on the net somewhere at a provisioning or hosting company?
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.