LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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


Reply
  Search this Thread
Old 03-05-2018, 10:33 AM   #1
Linux_nu_b
LQ Newbie
 
Registered: Feb 2018
Posts: 10

Rep: Reputation: Disabled
How to Configure a Static IP Address on Network Interface Centos 7


Hi,

I seem to have a problem getting internet after i have managed to statically assign my IP. Can someone help please?

i went to directory/etc/sysconfig/network-scripts
and used the command nano ifcfg-ens33 to edit the file to

TYPE=Ethernet
BOOTPROTO=static
NAME=ens33
UUID=edc2225f-f36e-4600-890e-3dbc73b16824
DEVICE=ens33
IPADDR=172.16.123.1
NETMASK=255.255.0.0
GATEWAY=172.16.0.0
ONBOOT=yes

I then hit ctrl X (y enter) to save the file and restarted it using /etc/init.d/network restart. I got a message saying OK and can see when i run ifconfig that the IP has changed to 172.16.123.1 as i wish but now i can't access the internet. Any ideas?

Last edited by Linux_nu_b; 03-05-2018 at 10:45 AM.
 
Old 03-05-2018, 10:50 AM   #2
tshikose
Member
 
Registered: Apr 2010
Location: Kinshasa, Democratic Republic of Congo
Distribution: RHEL, Fedora, CentOS
Posts: 473

Rep: Reputation: 91
Hi,

Are you sure your gateway should be set as below?
GATEWAY=172.16.0.0
 
Old 03-05-2018, 10:54 AM   #3
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-20-live-usb/ aix
Posts: 5,258

Rep: Reputation: 914Reputation: 914Reputation: 914Reputation: 914Reputation: 914Reputation: 914Reputation: 914Reputation: 914
i do this for my machines on my network:
Code:
[root@xbmc ~]# crontab -l
@reboot	(sleep 30 && ifconfig wlp4s0 netmask 255.255.255.0 192.168.1.105) &
 
Old 03-05-2018, 11:02 AM   #4
scasey
Senior Member
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.6
Posts: 3,827

Rep: Reputation: 1294Reputation: 1294Reputation: 1294Reputation: 1294Reputation: 1294Reputation: 1294Reputation: 1294Reputation: 1294Reputation: 1294
Quote:
Originally Posted by Linux_nu_b View Post
Code:
TYPE=Ethernet
BOOTPROTO=static
NAME=ens33
UUID=edc2225f-f36e-4600-890e-3dbc73b16824
DEVICE=ens33
IPADDR=172.16.123.1
NETMASK=255.255.0.0
GATEWAY=172.16.0.0
ONBOOT=yes
[Please use code tags to post code entries]
That configuration says that your router's IP (the gateway) is 172.16.0.0, which I doubt. Routers usually use IP addresses in the 192.168.x.y range, where x is usually 1 or 2 and y is almost always 1.
Additionally, if your router has a DHCP server, your static IP must be outside of the DHCP range to avoid conflicts.

As an example, my router's IP address is 192.168.0.1 and it's DHCP range is 192.168.0.100 to 192.168.0.199, so the settings for the static IP on my desktop are:
Code:
IPADDR=192.168.0.55 
NETMASK=255.255.255.0
GATEWAY=192.168.0.1
What is the IP address of your router?
What is the DHCP range in the router?
 
Old 03-05-2018, 12:32 PM   #5
Linux_nu_b
LQ Newbie
 
Registered: Feb 2018
Posts: 10

Original Poster
Rep: Reputation: Disabled
Iam trying to complete a task that requires my VM Linux server to be statically assigned an IP address in the segment 172.16.123.0/24 so i figured the gateway must be 172.16.0.0 and i was just going to set the ip as 172.16.123.1. Is this not correct then?
 
Old 03-05-2018, 12:34 PM   #6
tshikose
Member
 
Registered: Apr 2010
Location: Kinshasa, Democratic Republic of Congo
Distribution: RHEL, Fedora, CentOS
Posts: 473

Rep: Reputation: 91
Hi,

Please do not guess.
If the network does not provide DHCP, ask the network administrator.
Or get settings from another working machine on that same network.
 
Old 03-05-2018, 12:42 PM   #7
Linux_nu_b
LQ Newbie
 
Registered: Feb 2018
Posts: 10

Original Poster
Rep: Reputation: Disabled
The network does not yet provide DHCP. I have been trying to learn how to set DHCP first but had no joy so thought i would move on to setting the static IP then go back to DHCP. Here is the full task i am trying to complete.

Your Linux server must be statically assigned an IP address in the segment 172.16.123.0/24 with the Windows client being able to communicate with the server. A DHCP and a secure PureFTP server should be running on your Linux box. Your FTP server should only allow encrypted connections via Transport Layer Security (TLS).

I have managed to set up a pureFTP server so that it allows encrypted connections via TLS but i am struggling with the DHCP and the static IP. I have followed lots of tutorials but seem to be going round in circles.
 
Old 03-05-2018, 12:45 PM   #8
scasey
Senior Member
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.6
Posts: 3,827

Rep: Reputation: 1294Reputation: 1294Reputation: 1294Reputation: 1294Reputation: 1294Reputation: 1294Reputation: 1294Reputation: 1294Reputation: 1294
Quote:
Originally Posted by Linux_nu_b View Post
Iam trying to complete a task that requires my VM Linux server to be statically assigned an IP address in the segment 172.16.123.0/24 so i figured the gateway must be 172.16.0.0 and i was just going to set the ip as 172.16.123.1. Is this not correct then?
Apparently not, since it doesn't work. You can't guess what the gateway is, you must know*. Ask the person who assigned you the task what the gateway and netmask are, and what addresses are available (for example, .56 is not available on my network because it's already in use. It's almost guaranteed that the gateway is not 172.16.0.0...a better guess would be 172.16.123.1...but ASK someone! - or try what tshikose suggested about other computers on the same network.

*The gateway on my production server ends in .25, because the netblock serving it is much smaller than /24.

edit: Aha! This is homework?

Last edited by scasey; 03-05-2018 at 12:59 PM.
 
Old 03-05-2018, 02:35 PM   #9
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,230

Rep: Reputation: 724Reputation: 724Reputation: 724Reputation: 724Reputation: 724Reputation: 724Reputation: 724
Quote:
Originally Posted by Linux_nu_b View Post
The network does not yet provide DHCP. I have been trying to learn how to set DHCP first but had no joy so thought i would move on to setting the static IP then go back to DHCP. Here is the full task i am trying to complete.

Your Linux server must be statically assigned an IP address in the segment 172.16.123.0/24 with the Windows client being able to communicate with the server. A DHCP and a secure PureFTP server should be running on your Linux box. Your FTP server should only allow encrypted connections via Transport Layer Security (TLS).

I have managed to set up a pureFTP server so that it allows encrypted connections via TLS but i am struggling with the DHCP and the static IP. I have followed lots of tutorials but seem to be going round in circles.
Start by learning IPV4 addressing...

172.16.123.0/24:

Subnet: 172.16.123.0
Netmask: 255.255.255.0

In this subnet, which is the first usable network address? and the last?
 
Old 03-05-2018, 03:05 PM   #10
Linux_nu_b
LQ Newbie
 
Registered: Feb 2018
Posts: 10

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by keefaz View Post
Start by learning IPV4 addressing...

172.16.123.0/24:

Subnet: 172.16.123.0
Netmask: 255.255.255.0

In this subnet, which is the first usable network address? and the last?
I thought i new ip4 addressing but im obviously getting confused.

The first will be 172.16.123.1
and the last 172.16.123.254
right?

PS i have tried changing to

Code:
TYPE=Ethernet
BOOTPROTO=static
NAME=ens33
UUID=edc2225f-f36e-4600-890e-3dbc73b16824
DEVICE=ens33
IPADDR=172.16.123.1
NETMASK=255.255.255.0
GATEWAY=172.16.123.1
ONBOOT=yes
But still no luck
 
Old 03-05-2018, 03:43 PM   #11
jefro
Moderator
 
Registered: Mar 2008
Posts: 19,223

Rep: Reputation: 2928Reputation: 2928Reputation: 2928Reputation: 2928Reputation: 2928Reputation: 2928Reputation: 2928Reputation: 2928Reputation: 2928Reputation: 2928Reputation: 2928
I'm with the crowd on this.


"trying to complete a task that requires my VM Linux server to be statically assigned an IP address in the segment 172.16.123.0/24 so i figured the gateway must be 172.16.0.0 and i was just going to set the ip as 172.16.123.1. Is this not correct then"

VM's can have a virtual router. Each VM program is different. Not sure I know of a gateway of a vm that is 0.0. Could be. Where did you get this number from?
 
Old 03-05-2018, 04:00 PM   #12
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,230

Rep: Reputation: 724Reputation: 724Reputation: 724Reputation: 724Reputation: 724Reputation: 724Reputation: 724
Quote:
Originally Posted by Linux_nu_b View Post
I thought i new ip4 addressing but im obviously getting confused.

The first will be 172.16.123.1
and the last 172.16.123.254
right?

PS i have tried changing to

Code:
TYPE=Ethernet
BOOTPROTO=static
NAME=ens33
UUID=edc2225f-f36e-4600-890e-3dbc73b16824
DEVICE=ens33
IPADDR=172.16.123.1
NETMASK=255.255.255.0
GATEWAY=172.16.123.1
ONBOOT=yes
But still no luck
The gateway is the router connected to your subnet that will forward traffic to other network.
If you assign GATEWAY value to your host IP, that means your host is now the gateway and it will need another network interface to forward traffic.

If host succeded to connect to internet before you set the IP as static, try to revert to old config using dhcp and use ' route -n ' command to figure out what is the gateway IP

Last edited by keefaz; 03-05-2018 at 04:10 PM.
 
1 members found this post helpful.
Old 03-12-2018, 04:00 PM   #13
Linux_nu_b
LQ Newbie
 
Registered: Feb 2018
Posts: 10

Original Poster
Rep: Reputation: Disabled
Thumbs up Thanks

Managed to get this working by using the following configuration.

Thanks to those that tried to help, you helped to steer me in the right direction.

HWADDR=00:0C:29:FA:4E:5E
TYPE=Ethernet
# Static IP Address #
BOOTPROTO=none
# Server IP #
IPADDR=172.16.123.5
# Netmask #
NETMASK=255.255.255.0
# Default Gateway IP #
GATEWAY=172.16.123.3
# DNS Servers #
DNS1=172.16.123.3
DNS2=8.8.8.8
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
# Disable ipv6 #
IPV6INIT=no
NAME= ens33
# Optional - This is system specific and can be created using 'uuidgen enp0s3' command #
UUID=3b08d9c3-7ac8-425b-b5d8-ce37eec273c8
DEVICE= ens33
# Activate on Boot #
ONBOOT=yes
# Default Domain Search #
DOMAIN=example.local
 
Old 03-12-2018, 04:33 PM   #14
jefro
Moderator
 
Registered: Mar 2008
Posts: 19,223

Rep: Reputation: 2928Reputation: 2928Reputation: 2928Reputation: 2928Reputation: 2928Reputation: 2928Reputation: 2928Reputation: 2928Reputation: 2928Reputation: 2928Reputation: 2928
Thanks for the update and solution.
 
  


Reply

Tags
centos7, static ip


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Configure NIC(Network Interface Card) bonding in CentOS 7 / RHEL 7 LXer Syndicated Linux News 0 08-31-2015 08:52 PM
How to Configure Network Static IP Address and Manage Services on RHEL/CentOS 7.0 onebuck CentOS 0 07-21-2014 01:44 AM
[SOLVED] Network Interface Loses Static IP Address When Cable Is Removed D1ver Linux - Networking 2 02-22-2012 11:21 PM
static ipv6 address not showing on eth0 interface gitecravirs Linux - Newbie 0 06-10-2009 09:01 AM
configure server use a static IP address limit_me Linux - Server 3 11-08-2008 11:42 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:39 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration