LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 06-12-2005, 12:06 AM   #1
carlosinfl
Senior Member
 
Registered: May 2004
Location: Orlando, FL
Distribution: Arch
Posts: 2,905

Rep: Reputation: 77
Setting Static IP via CLI?


I need to set my IP to stay what it is listed below.

***********************************

root@carlos:/# ifconfig
eth0 Link encap:Ethernet HWaddr 00:04:61:58A:5D
inet addr:192.168.1.101 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fe80::204:61ff:fe58:da5d/64 Scope:Link
UP BROADCAST NOTRAILERS RUNNING MULTICAST MTU:1500 Metric:1
RX packets:16323 errors:0 dropped:0 overruns:0 frame:0
TX packets:12252 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:15152065 (14.4 Mb) TX bytes:1941797 (1.8 Mb)
Interrupt:5

lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:34 errors:0 dropped:0 overruns:0 frame:0
TX packets:34 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:2180 (2.1 Kb) TX bytes:2180 (2.1 Kb)

*************************************

As you can see my dynamic (local) IP is 192.168.1.101 & I need to make sure that this remains reguardless how many reboots are done and no matter what happens. Is there a way to set this via CLI?

Thanks for any info!
 
Old 06-12-2005, 12:11 AM   #2
masand
LQ Guru
 
Registered: May 2003
Location: INDIA
Distribution: Ubuntu, Solaris,CentOS
Posts: 5,522

Rep: Reputation: 69
for slack try editing this file

/etc/rc.d/rc.inet1.conf


regards
 
Old 06-12-2005, 12:46 AM   #3
RossB
Novell Adv. Tech. Training Engineer
 
Registered: Jul 2004
Distribution: Knoppix/Mint
Posts: 47

Rep: Reputation: 15
if you're running redhat, set the address statically with the redhat-config-network tool.

If you're running SUSE, use the yast tool and set it static.

If you're running some other version of Linux, try the netconfig tool.

Failing that, look on Google, such as: "How to set static IP in DistroX"

So, what distro are you running?

Ross
 
Old 06-12-2005, 06:14 AM   #4
DavidPhillips
LQ Guru
 
Registered: Jun 2001
Location: South Alabama
Distribution: Fedora / RedHat / SuSE
Posts: 7,163

Rep: Reputation: 58
the command is...

ifconfig eth0 192.168.1.101
route add default gw <gateway ip address>

if you do not know the gateway address run route while it's setup..




/sbin/route -n |grep UG
0.0.0.0 192.168.0.1 0.0.0.0 UG 0 0 0 eth0


route add default gw 192.168.0.1


If your switching from dhcp to static also be sure to set the DNS servers in /etc/resolv.conf
 
Old 06-12-2005, 07:29 AM   #5
ravee
Member
 
Registered: Jan 2005
Location: India
Distribution: Fedora Core 2
Posts: 83

Rep: Reputation: 15
Maybe this link might help:
http://linuxhelp.blogspot.com/2005/0...p-address.html

Ravi
 
Old 06-12-2005, 07:41 AM   #6
masand
LQ Guru
 
Registered: May 2003
Location: INDIA
Distribution: Ubuntu, Solaris,CentOS
Posts: 5,522

Rep: Reputation: 69
Quote:
Originally posted by DavidPhillips
the command is...

ifconfig eth0 192.168.1.101
route add default gw <gateway ip address>

if you do not know the gateway address run route while it's setup..




/sbin/route -n |grep UG
0.0.0.0 192.168.0.1 0.0.0.0 UG 0 0 0 eth0


route add default gw 192.168.0.1


If your switching from dhcp to static also be sure to set the DNS servers in /etc/resolv.conf
as the thread starter asked that he does not want that the ip address should change even after reboot
won't this method that u have given require the user to again run this command afer reboot

regards
 
Old 06-12-2005, 08:10 PM   #7
DavidPhillips
LQ Guru
 
Registered: Jun 2001
Location: South Alabama
Distribution: Fedora / RedHat / SuSE
Posts: 7,163

Rep: Reputation: 58
Yes it will.

It's just that they said CLI which is what that demonstrates.

For it to stay the configuration is surely going to need to be added to startup scripts.


I guess the thread title does not really fit with the question asks.

Last edited by DavidPhillips; 06-12-2005 at 08:12 PM.
 
Old 06-13-2005, 01:47 AM   #8
masand
LQ Guru
 
Registered: May 2003
Location: INDIA
Distribution: Ubuntu, Solaris,CentOS
Posts: 5,522

Rep: Reputation: 69
"I guess the thread title does not really fit with the question asks."

yes i agree on this

while setting ip through CLI, ifconfig works in all cases no matter what the OS is

regards
 
Old 06-13-2005, 01:18 PM   #9
Robert G. Hays
Member
 
Registered: Jan 2003
Location: Atlanta, Ga., USA
Distribution: Gentoo, Mandrake, ~others
Posts: 157

Rep: Reputation: 30
Just for completeness, what masand said is correct, and to not have to type those commands every time you boot -- the ones that DavidPhillips started with -- they would, for most distros!, go at the end of /etc/rc.d/rc.local. It might, however, make sense to learn just enough of the specifics of *your* distro(s)' startup files to be able to put it earlier in the sequence.

Note, one of my personal peeves with MonopleSoft is that they start the NIC and networking before pretty much anything else, leaving a time-Window for malware to sneak in. Thus I like to set my NICs to NOT start on startup, and have rc.local finally bring them up after all else, including FW & AV !!!, has started & stabliized. Just a thought... YMMV.

robert.
 
Old 06-13-2005, 07:45 PM   #10
DavidPhillips
LQ Guru
 
Registered: Jun 2001
Location: South Alabama
Distribution: Fedora / RedHat / SuSE
Posts: 7,163

Rep: Reputation: 58
Yes, that is important.

One way is to set policies that disable all traffic, bring up the interface, and finally set the rules and then change the policies.
 
  


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
setting a static IP roenstad Linux - Newbie 1 10-02-2005 02:56 AM
Setting a static IP hongman Linux - Networking 6 02-22-2005 05:07 AM
Setting Static IP smurfix Debian 6 02-20-2005 03:07 PM
setting a static IP EMHagerty Linux - Networking 1 09-09-2004 03:15 PM
Setting default gateway from CLI? Pcghost Linux - Networking 1 03-20-2003 10:38 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

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