LinuxQuestions.org
Review your favorite Linux distribution.
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 07-02-2016, 11:34 AM   #1
sysmicuser
Member
 
Registered: Mar 2010
Posts: 332

Rep: Reputation: 0
Not getting a static IP for CentOS 7


Good Folks,

Here are the network configuration files:
Code:
[root@agent1 ~]# cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.1.2 puppet master
192.168.1.3 agent1 machine1
192.168.1.4 agent2 machine2
192.168.1.5 agent3 machine3
[root@agent1 ~]# cat /etc/sysconfig/network
# Created by anaconda
NETWORKING=yes
NETWORKING_IPV6=no
HOSTNAME=agent1
GATEWAY=192.168.1.1
[root@agent1 ~]# cat /etc/sysconfig/network-scripts/ifcfg-enp0s3 
TYPE=Ethernet
BOOTPROTO=static
DEFROUTE=yes
IPV4_FAILURE_FATAL=yes
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
NAME=eth0
UUID=9b49c161-f7b4-418d-ae5f-a4fae294d302
DEVICE=eth0
ONBOOT=no
IPADDR=192.168.1.3
PREFIX=32
GATEWAY=192.168.1.1
DNS1=192.168.1.1
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes
[root@agent1 ~]# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 08:00:27:84:c2:b6 brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.10/24 brd 192.168.1.255 scope global dynamic enp0s3
       valid_lft 85698sec preferred_lft 85698sec
    inet6 fe80::a00:27ff:fe84:c2b6/64 scope link 
       valid_lft forever preferred_lft forever
3: enp0s8: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 08:00:27:18:f1:a8 brd ff:ff:ff:ff:ff:ff
    inet 192.168.99.100/24 brd 192.168.99.255 scope global dynamic enp0s8
       valid_lft 996sec preferred_lft 996sec
    inet6 fe80::a00:27ff:fe18:f1a8/64 scope link 
       valid_lft forever preferred_lft forever
4: virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN 
    link/ether 00:00:00:00:00:00 brd ff:ff:ff:ff:ff:ff
    inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0
       valid_lft forever preferred_lft forever
5: virbr0-nic: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast state DOWN qlen 500
    link/ether 52:54:00:44:89:62 brd ff:ff:ff:ff:ff:ff
[root@agent1 ~]#
Not sure what I am missing to have my static IP??

Yes, I am connected to internet by ping command
 
Old 07-02-2016, 12:19 PM   #2
michaelk
Moderator
 
Registered: Aug 2002
Posts: 14,929

Rep: Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520
Code:
TYPE=Ethernet
BOOTPROTO=static
DEFROUTE=yes
IPV4_FAILURE_FATAL=yes
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
NAME=eth0
UUID=9b49c161-f7b4-418d-ae5f-a4fae294d302
DEVICE=eth0
ONBOOT=no
IPADDR=192.168.1.3
PREFIX=32
GATEWAY=192.168.1.1
DNS1=192.168.1.1
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes
Try the following changes. Without the ONBOOT=yes directive it will not start at boot time. Even if network manager is running the NM_CONTROLLED=no directive will keep it from managing the interface.

ONBOOT=yes
NM_CONTROLLED=NO
 
1 members found this post helpful.
Old 07-02-2016, 10:43 PM   #3
sysmicuser
Member
 
Registered: Mar 2010
Posts: 332

Original Poster
Rep: Reputation: 0
That worked I am however not having any access to internet now.

I read https://www.centos.org/forums/viewtopic.php?t=44838 that for static IP we don't need NetworkManager and dhcp so I uninstalled it using
Code:
yum remove dhclient NetworkManager
reboot
As of now, if I type dhclient I do not get get connected to internet which I was before. That is right as I have "uninstalled" dhcp package.

However I believe I have static IP but no connection to outside world.

Code:
[root@agent1 ~]# cat /etc/resolv.conf 
; generated by /usr/sbin/dhclient-script
search netgear
nameserver 192.168.1.1
[root@agent1 ~]# ping -c 5 google.com
ping: unknown host google.com
[root@agent1 ~]# cat /etc/sysconfig/network-scripts/ifcfg-enp0s3 
TYPE=Ethernet
BOOTPROTO=static
DEFROUTE=yes
IPV4_FAILURE_FATAL=yes
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
NAME=enp0s3
UUID=9b49c161-f7b4-418d-ae5f-a4fae294d302
DEVICE=enp0s3
ONBOOT=yes
NM_CONTROLLED=NO
IPADDR=192.168.1.3
PREFIX=32
GATEWAY=192.168.1.1
DNS1=192.168.1.1
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes
[root@agent1 ~]# cat /etc/sysconfig/network
# Created by anaconda
NETWORKING=yes
NETWORKING_IPV6=no
GATEWAY=192.168.1.1
[root@agent1 ~]# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 08:00:27:84:c2:b6 brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.3/32 brd 192.168.1.3 scope global enp0s3
       valid_lft forever preferred_lft forever
    inet6 fe80::a00:27ff:fe84:c2b6/64 scope link 
       valid_lft forever preferred_lft forever
3: enp0s8: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN qlen 1000
    link/ether 08:00:27:18:f1:a8 brd ff:ff:ff:ff:ff:ff
4: virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN 
    link/ether 52:54:00:44:89:62 brd ff:ff:ff:ff:ff:ff
    inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0
       valid_lft forever preferred_lft forever
5: virbr0-nic: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast master virbr0 state DOWN qlen 500
    link/ether 52:54:00:44:89:62 brd ff:ff:ff:ff:ff:ff
[root@agent1 ~]#
Please note that this is all on VirtualBox installed on Windows 10. I have two network adapters Adapter 1 Bridege andAdapter 2 Host only.

I am hoping that this information helps us to identify and solve the problem

Last edited by sysmicuser; 07-02-2016 at 10:45 PM.
 
Old 07-02-2016, 11:08 PM   #4
Doug G
Member
 
Registered: Jul 2013
Posts: 594

Rep: Reputation: Disabled
Personally, I just use NetworkManager to give an interface a static IP, using the NM-applet (gui), or nmtui (cli). I have a few centos7 systems with static IP's through NM, and have never had a problem. Setting up a bridged connection is about the only time I still go back to editing the network files.
 
Old 07-02-2016, 11:37 PM   #5
lazydog
Member
 
Registered: Dec 2003
Location: The Key Stone State
Distribution: CentOS Sabayon and now Gentoo
Posts: 776
Blog Entries: 1

Rep: Reputation: 122Reputation: 122
Quote:
Originally Posted by sysmicuser View Post
Code:
[root@agent1 ~]# cat /etc/resolv.conf 
; generated by /usr/sbin/dhclient-script
search netgear
nameserver 192.168.1.1
[root@agent1 ~]# ping -c 5 google.com
ping: unknown host google.com
You have your dns server set to 192.168.1.1 is there a dns server at that ip address? If not then that is why you cannot resolve google.com and you are going to have to configure a dns server before this will work
 
Old 07-03-2016, 06:00 AM   #6
sysmicuser
Member
 
Registered: Mar 2010
Posts: 332

Original Poster
Rep: Reputation: 0
Quote:
You have your dns server set to 192.168.1.1 is there a dns server at that ip address? If not then that is why you cannot resolve google.com and you are going to have to configure a dns server before this will work
I set it now to the one I got from My internet provider. No luck still. I cannot install package anymore which make me blocked. Sev 1 issue.
 
Old 07-03-2016, 07:42 AM   #7
Emerson
LQ Guru
 
Registered: Nov 2004
Location: Saint Amant, Acadiana
Distribution: Gentoo ~arch
Posts: 5,872

Rep: Reputation: Disabled
You need to set route to the default gateway.
 
Old 07-03-2016, 09:04 AM   #8
sysmicuser
Member
 
Registered: Mar 2010
Posts: 332

Original Poster
Rep: Reputation: 0
I did by the following but have no charm

Code:
[root@agent1 ~]# route add default gw 192.168.1.1 enp0s3
SIOCADDRT: Network is unreachable
[root@agent1 ~]# route add 192.168.1.1 enp0s3
[root@agent1 ~]# systemctl status network.service
● network.service - LSB: Bring up/down networking
   Loaded: loaded (/etc/rc.d/init.d/network)
   Active: active (exited) since Sun 2016-07-03 22:56:51 AEST; 1min 35s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 12889 ExecStop=/etc/rc.d/init.d/network stop (code=exited, status=0/SUCCESS)
  Process: 13049 ExecStart=/etc/rc.d/init.d/network start (code=exited, status=0/SUCCESS)

Jul 03 22:56:46 agent1 systemd[1]: Starting LSB: Bring up/down networking...
Jul 03 22:56:47 agent1 network[13049]: Bringing up loopback interface:  [  OK  ]
Jul 03 22:56:51 agent1 network[13049]: Bringing up interface enp0s3:  [  OK  ]
Jul 03 22:56:51 agent1 systemd[1]: Started LSB: Bring up/down networking.
[root@agent1 ~]#
Please do note that that I have removed DNS1 and DNS2 entries from ifcfg-enp0s3 file. I think its useless and I don't require for static ip configuration.
 
Old 07-03-2016, 09:53 AM   #9
Emerson
LQ Guru
 
Registered: Nov 2004
Location: Saint Amant, Acadiana
Distribution: Gentoo ~arch
Posts: 5,872

Rep: Reputation: Disabled
Code:
ip a
will tell what interfaces you have, ethtool can be used to check the status of physical layer.
 
Old 07-03-2016, 09:54 AM   #10
sysmicuser
Member
 
Registered: Mar 2010
Posts: 332

Original Poster
Rep: Reputation: 0
Unable to connect to Internet and router

Code:
[root@agent1 ~]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 08:00:27:84:c2:b6 brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.3/32 brd 192.168.1.3 scope global enp0s3
       valid_lft forever preferred_lft forever
    inet6 fe80::a00:27ff:fe84:c2b6/64 scope link 
       valid_lft forever preferred_lft forever
3: virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN 
    link/ether 52:54:00:44:89:62 brd ff:ff:ff:ff:ff:ff
    inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0
       valid_lft forever preferred_lft forever
4: virbr0-nic: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast master virbr0 state DOWN qlen 500
    link/ether 52:54:00:44:89:62 brd ff:ff:ff:ff:ff:ff
[root@agent1 ~]#
Code:
[root@agent1 ~]# ethtool enp0s3
Settings for enp0s3:
	Supported ports: [ TP ]
	Supported link modes:   10baseT/Half 10baseT/Full 
	                        100baseT/Half 100baseT/Full 
	                        1000baseT/Full 
	Supported pause frame use: No
	Supports auto-negotiation: Yes
	Advertised link modes:  10baseT/Half 10baseT/Full 
	                        100baseT/Half 100baseT/Full 
	                        1000baseT/Full 
	Advertised pause frame use: No
	Advertised auto-negotiation: Yes
	Speed: 1000Mb/s
	Duplex: Full
	Port: Twisted Pair
	PHYAD: 0
	Transceiver: internal
	Auto-negotiation: on
	MDI-X: off (auto)
	Supports Wake-on: umbg
	Wake-on: d
	Current message level: 0x00000007 (7)
			       drv probe link
	Link detected: yes

[root@agent1 ~]# ethtool --test enp0s3 online
The test result is PASS
The test extra info:
Register test  (offline)	 0
Eeprom test    (offline)	 0
Interrupt test (offline)	 0
Loopback test  (offline)	 0
Link test   (on/offline)	 0

[root@agent1 ~]#
Apologies but I am in no mans land about my my network

Last edited by sysmicuser; 07-03-2016 at 10:05 AM. Reason: Cannot connect to internet and /or router
 
Old 07-03-2016, 10:10 AM   #11
Emerson
LQ Guru
 
Registered: Nov 2004
Location: Saint Amant, Acadiana
Distribution: Gentoo ~arch
Posts: 5,872

Rep: Reputation: Disabled
Code:
inet 192.168.1.3/32 brd 192.168.1.3 scope global enp0s3
Netmask 32 !? No wonder broadcast is off as well.
 
Old 07-03-2016, 10:23 AM   #12
sysmicuser
Member
 
Registered: Mar 2010
Posts: 332

Original Poster
Rep: Reputation: 0
lo I thought you wanted to me to run the command lol I later realized that is the output from ip a command.

May I know what you mean by your comment ?
 
Old 07-03-2016, 11:42 AM   #13
Emerson
LQ Guru
 
Registered: Nov 2004
Location: Saint Amant, Acadiana
Distribution: Gentoo ~arch
Posts: 5,872

Rep: Reputation: Disabled
Netmask /32 would be 255.255.255.255. See? Just one host per network! Obviously an one-host network cannot connect to any other machines!
 
Old 07-03-2016, 11:58 AM   #14
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,599

Rep: Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241
I think you need to drop the "NM_CONTROLLED=NO", I think that prevents the network from being started UNLESS you use the "networks" script instead of NetworkManager.

You do need to add a "NETMASK=255.255.255.0" or you do not get a functioning network (this should set the /24 for a class C network).

There is some ambiguity in the BOOTPROTO. I have "none" rather than "static". I know both used to work, but it is possible the "static" has a different connotation. If things work with the other changes, leave it as "static" if it still doesn't work, try "none" just to see what happens.
reference:http://unix.stackexchange.com/questi...tc-resolv-conf

Last edited by jpollard; 07-03-2016 at 12:02 PM.
 
Old 07-03-2016, 06:22 PM   #15
sysmicuser
Member
 
Registered: Mar 2010
Posts: 332

Original Poster
Rep: Reputation: 0
Hello Kind Sir

I removed NM_CONTROLLED=NO and ONBOOTPRO=none. I however don't know how to
Quote:
You do need to add a "NETMASK=255.255.255.0" or you do not get a functioning network (this should set the /24 for a class C network).
That means add netmask I don't know. Would appreciate if you can guide.

As of now configuration still doesn't allow ping to router and google.com
Code:
[root@agent1 ~]# ping 192.168.1.1
connect: Network is unreachable
[root@agent1 ~]# ping google.com
ping: unknown host google.com
[root@agent1 ~]# cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.1.2 puppet master
192.168.1.3 agent1 machine1
192.168.1.4 agent2 machine2
192.168.1.5 agent3 machine3
[root@agent1 ~]# cat /etc/sysconfig/network
# Created by anaconda
GATEWAY=192.168.1.1
[root@agent1 ~]# 

[root@agent1 ~]# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 08:00:27:84:c2:b6 brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.3/32 brd 192.168.1.3 scope global enp0s3
       valid_lft forever preferred_lft forever
    inet6 fe80::a00:27ff:fe84:c2b6/64 scope link 
       valid_lft forever preferred_lft forever
3: virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN 
    link/ether 52:54:00:44:89:62 brd ff:ff:ff:ff:ff:ff
    inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0
       valid_lft forever preferred_lft forever
4: virbr0-nic: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast master virbr0 state DOWN qlen 500
    link/ether 52:54:00:44:89:62 brd ff:ff:ff:ff:ff:ff
[root@agent1 ~]# cat /etc/sysconfig/network-scripts/ifcfg-enp0s3 
TYPE=Ethernet
BOOTPROTO=none
DEFROUTE=yes
IPV4_FAILURE_FATAL=yes
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
NAME=enp0s3
UUID=9b49c161-f7b4-418d-ae5f-a4fae294d302
DEVICE=enp0s3
ONBOOT=yes
IPADDR=192.168.1.3
PREFIX=32
GATEWAY=192.168.1.1
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes
[root@agent1 ~]#
 
  


Reply


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
Static IP not working in CentOS 6.5 Noo Linux - Newbie 16 03-03-2016 07:53 PM
CentOS 6 - Persistent Static Route karim.wallani Linux - Networking 5 06-29-2012 05:42 PM
Centos 6.2 set static IP velvetbulldozer Linux - Server 6 02-26-2012 08:32 AM
[SOLVED] installing centos 5.3 with static ip? windstory Linux - Newbie 4 10-12-2009 09:55 PM
CentOS DHCP to Static mitchell2345 Linux - Networking 5 11-01-2008 11:38 AM


All times are GMT -5. The time now is 12:54 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