How can I tell if my Linux server has a static or dynamic IP address assigned to it?
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
How can I tell if my Linux server has a static or dynamic IP address assigned to it?
Hi there,
I work for a small company and have been tasked with managing a server that runs linux. My boss has asked me to assign a fixed IP to the server. The server is not new, it has been up and running for months.
I have a hunch that it already has a fixed IP address, but how can I tell for sure? I can run the "ifconfig" command, and it gives me the IP address and some other information. I'd post the results here if I could, but it's on a different machine.
So, is there a command I can run to see if my server has a static or dynamic IP? I'm a total beginner so it would be helpful if you don't get too technical.
Start by telling us which distribution (aka name) and version of Linux you have. That'll help enormously.
If you don't already know, open a cmd line terminal and try try the following cmds
uname -a
cat /etc/*release*
and post the results.
Also, post the output from ifconfig.
You can use cat to view a file. In a command window run this command as root
Code:
cat /etc/network/interfaces
I for example have a static IP so this is what mine looks like
Code:
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
allow-hotplug eth0
iface eth0 inet static
address 10.1.1.20
netmask 255.255.255.0
network 10.1.1.0
broadcast 10.1.1.255
gateway 10.1.1.1
If you have a dynamic IP (DHCP) it will look like this
Code:
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
allow-hotplug eth0
iface eth0 inet dhcp
Well I don't know about this being distro-dependent - how about this: use ifconfig to note down your IP address, then turn off and turn on your net connection, and (preferably the next day or something) run ifconfig again and see whether you have the same IP - this should solve your problem no?
But this obviously presupposes that you won't get the same IP twice which isn't guaranteed, and may very well be the case.
Well I don't know about this being distro-dependent - how about this: use ifconfig to note down your IP address, then turn off and turn on your net connection, and (preferably the next day or something) run ifconfig again and see whether you have the same IP - this should solve your problem no?
But this obviously presupposes that you won't get the same IP twice which isn't guaranteed, and may very well be the case.
I think stopping and restarting the networking is probably something the OP would rather avoid. Also not only is it possible that the IP will be the same even in the DHCP case, but very likely since DHCP clients usually request the same IP that they had previously.
A distro indep. way could just be looking in /var/log/messages.
Start by telling us which distribution (aka name) and version of Linux you have. That'll help enormously.
If you don't already know, open a cmd line terminal and try try the following cmds
uname -a
cat /etc/*release*
and post the results.
Also, post the output from ifconfig.
Thanks for everyone's help. Since I don't know how to email the results from that machine, the only thing I could think of was to take a photo of the screen. Here are the results of the three commands.
This machine has been shut down and restarted a few times, and the IP address has always been the same: 192.168.1.109. That's why I suspect that it is configured for static IP.
Check if you have /etc/sysconfig/network-scripts/ifcfg-eth0 file and whats its contents are.
It seems to be where CentOS keeps its network configuration options.
Check if you have /etc/sysconfig/network-scripts/ifcfg-eth0 file and whats its contents are.
It seems to be where CentOS keeps its network configuration options.
I ran this command and it sure looks like it has been set as static. Is that what the "BOOTPROTO=static" means?
Well there you go. It says in your /etc/sysconfig/network-scripts/ifcfg-eth0 file BOOTPROTO=STATIC. That tells you right there it is a static (Fixed) IP.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.