LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
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 09-08-2015, 06:46 AM   #1
itdev
LQ Newbie
 
Registered: Sep 2015
Posts: 3

Rep: Reputation: Disabled
assigning static ip


I want to assign static ip to my centos server. so i made following changes to /etc/sysconfig/network-scripts/ifcfg-eth0 and the file looks like this.
DEVICE=eth0
TYPE=Ethernet
UUID=16e5310e-f477-4031-a17e-121a8c856fa1
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=static
DEFROUTE=yes
IPV4_FAILURE_FATAL=yes
IPV6INIT=no
NAME="System eth0"
HWADDR=FC:AA:14:EF:51:41
IPADDR=192.168.0.41
NETMASK=255.255.255.0

PEERDNS=yes
PEERROUTES=yes

but after restarting the system, i am unable to access internet until i run dhclient command at the prompt.
kindly please someone help me in fixing this.
 
Old 09-08-2015, 07:37 AM   #2
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513
Try using "BOOTPROTO=none".
 
Old 09-08-2015, 08:15 AM   #3
itdev
LQ Newbie
 
Registered: Sep 2015
Posts: 3

Original Poster
Rep: Reputation: Disabled
THanks for the reply.

I sorted out the problem by entering the "dhclient eth0" to the file /etc/rc.d/rc.local, so that i no need to run dhclient cmd after rebooting the server everytime.

NOW my ip is 192.168.0.41.

But i am able to access the server even by entering my old ip as http://192.168.0.7/myapp

is there any way to restrict it.
 
Old 09-08-2015, 09:39 AM   #4
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,691

Rep: Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894
By setting up a static IP address your computer does not automatically acquire any DNS server information so you can not access the Internet using URLs I.e. Google.com etc. if you run dhclient then from rc.local you will reassign the IP address as well as get the DNS server info.

I'm lazy and use the router's dhclient address reservation feature but you should be able to use network manager setup if running a desktop or system-config-network from the command line. Fill in the info using your ISP DNS servers or many use google's 8.8.8.8
 
Old 09-09-2015, 02:10 AM   #5
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,358

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
Personally I've always found Network Mgr to be a pain, so I always turn it off, then it will just do as its told.
(As michaelk points out, this only sets the local IP - it won't update DNS)
 
Old 09-09-2015, 06:58 AM   #6
tronayne
Senior Member
 
Registered: Oct 2003
Location: Northeastern Michigan, where Carhartt is a Designer Label
Distribution: Slackware 32- & 64-bit Stable
Posts: 3,541

Rep: Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065
Simply edit (or create) /etc/resolv.conf (should be there). For example, here's what it looks like for Google's open DNS servers:
Code:
search com
# Google Free DNS Servers
nameserver 8.8.8.8
nameserver 8.8.4.4
You only need two, more is just overkill.

I would note that router DNS may cease working after some period of time; this happens with some Linksys routers and I've seen it on others. After a while, it just quits and needs to be restarted.

The configuration I use for fixed-IP on all my systems looks like this:
Code:
# Config information for eth0:
IPADDR[0]="192.168.1.10"
NETMASK[0]="255.255.255.0"
USE_DHCP[0]=""
DHCP_HOSTNAME[0]=""

# Default gateway IP address:
GATEWAY="192.168.1.1"
Keep in mind that DHCP usually starts leasing at 192.168.1.100, so keep your fixed-IP below that.

Hope this helps some.

Oops! Forgot to mention /etc/hosts.

This is my /etc/hosts file for four servers and one network printer:
Code:
# For loopbacking.
127.0.0.1               localhost

# Local servers
192.168.1.10            fubar.lan fubar
192.168.1.15            OfficeJet
192.168.1.20            snafu.lan snafu
192.168.1.30            pita.lan pita
192.168.1.2             hicl01.lan hicl01
The names are the hostname you assigned to the box during installation. fubar.lan is the actual name of the host, fubar is how you refer to it without the .lan.

So, you ping snafu from fubar (or, for that matter ping fubar from fubar) and get a response. You also ssh fubar from any other server without having to enter the numeric address.

Every box has the same /etc/hosts file, every box can access the network printer (HPLIP runs on every system; HPLIP set up also sets up CUPS).

Makes life easier.
 
Old 09-09-2015, 03:17 PM   #7
think4pai
LQ Newbie
 
Registered: Sep 2015
Posts: 2

Rep: Reputation: Disabled
the original configuration seems to be missing the gateway, an easy way to check is by running "ip route" and make sure you have a default gateway. By getting the ip using dhcp, you will also have a default gateway assigned, the "ip route" cmd will show it too.
 
Old 09-09-2015, 03:47 PM   #8
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573

Rep: Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142
You're missing gateway and dns1/2 in your ifcfg file, and change bootproto from static to none.

An example from one of my systems:
Code:
$ cat /etc/sysconfig/network-scripts/ifcfg-eth0 
DEVICE=eth0
TYPE=Ethernet
UUID=197becd8-fa4e-4d81-9ebe-d9a51709507a
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=none
HWADDR=0C:C4:7A:02:8C:70
IPADDR=192.168.1.136
PREFIX=24
GATEWAY=192.168.1.1
DNS1=192.168.1.2
DNS2=192.168.1.3
DEFROUTE=yes
IPV4_FAILURE_FATAL=yes
IPV6INIT=no
NAME="System eth0"
192.168.1.2/3 are VMs on my network running dnsmasq to provide local name resolution.

NetworkManager will use the DNS1/2 entries in your ifcfg file to populate resolv.conf, you shouldn't modify resolv.conf manually if you're using NetworkManager.
 
  


Reply



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
Having an odd issue assigning a static IP in Debian. Rehumanize Linux - Networking 3 07-09-2008 11:30 PM
Ubuntu 6.06 Server(Assigning Static IP) TechMansoor Linux - Networking 4 12-18-2006 02:26 PM
Cannot ping router after assigning static IP mickwombat Linux - Networking 5 06-11-2006 06:09 PM
Assigning Static IP Problem canuck_barlow Linux - Newbie 5 01-06-2006 02:54 PM
assigning static ip vcheah Linux - Networking 5 12-25-2001 06:41 PM

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

All times are GMT -5. The time now is 04:12 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
Open Source Consulting | Domain Registration