LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 08-14-2006, 05:30 PM   #1
helptonewbie
Member
 
Registered: Aug 2006
Location: England Somewhere
Distribution: Mandriva, PCLinuxOS, Karoshi, Suse, Redhat, Ubuntu
Posts: 518

Rep: Reputation: 39
Unhappy Configure network card via the console??




Using mandriva, i would like to learn how i can configure my eth0 network card via the bash console. Currently i can change the i address and so on using "ifconfig eth0 192.168.1.2" for example. This then stops my internet working as it can't find the gateway so i then need to use "route add default gw 192.168.1.1 dev eth0" which then of course gets my internet back. I was wondering if there is another way i can do a similar thing but maybe via a script automatically changing the ip address in "/etc/sysconfig/network-scripts/ifcfg-eth0" and then just running "/etc/init.d/network restart" to get the network card restarted all automatically. I'd rather it be done like this and not the other method i specified earlier, so i need to know a script that can basically automatically open the file, point to the "IPADDR=" part of the file and then edit the ip address that is already in place. Is that possible anyone? All help and other methods welcome. Thanks in advance.
 
Old 08-14-2006, 06:14 PM   #2
gizza23
Member
 
Registered: Jun 2005
Location: Chicago, IL, USA
Distribution: Fedora Core, CentOS
Posts: 188

Rep: Reputation: 31
That's totally possible. Check out this sample configuration for that file.

Code:
#
#/etc/sysconfig/network-scripts/ifcfg-eth0
#

DEVICE=eth0
IPADDR=192.168.0.104
NETMASK=255.255.255.0
BROADCAST=192.168.0.255
NETWORK=192.168.0.0
BOOTPROTO=static
HWADDR=00:00:00:00:00:00
ONBOOT=yes
GATEWAY=192.168.0.1

Last edited by gizza23; 08-14-2006 at 06:17 PM.
 
Old 08-14-2006, 06:53 PM   #3
helptonewbie
Member
 
Registered: Aug 2006
Location: England Somewhere
Distribution: Mandriva, PCLinuxOS, Karoshi, Suse, Redhat, Ubuntu
Posts: 518

Original Poster
Rep: Reputation: 39
thanks but thats not really answered my question. i'm interested in finding a script or something that can do this, maybe i'm mistaken but al you've shown me is a sample file. i guess another idea is i can have several files and then just change the name of the file to be that of the actual file and then change the actual file to be some other name. Have many files all with different settings and then just restart the network after changing the file name using the "mv" command or such like. But i'm looking more towards the user needs to type in an ip address at the appropriate time and the "IPADDR=" in the current file is changed for the new one given and then the network restarted. OR that i have a variable and somehow give the IPADDR="MyVariableName" type of thing. If anyone understand what i'm getting at.??. i dont think i do sometimes
 
Old 08-15-2006, 01:01 PM   #4
helptonewbie
Member
 
Registered: Aug 2006
Location: England Somewhere
Distribution: Mandriva, PCLinuxOS, Karoshi, Suse, Redhat, Ubuntu
Posts: 518

Original Poster
Rep: Reputation: 39
Unhappy

anybody have any ideas?
 
Old 08-15-2006, 02:21 PM   #5
andrewdodsworth
Member
 
Registered: Oct 2003
Location: United Kingdom
Distribution: SuSE 10.0 - 11.4
Posts: 347

Rep: Reputation: 30
Have a look at 'ed' or 'sed' - they're editors that you can run against a file using scripts for the changes you want. Haven't used them myself but a quick look at 'man sed' looks as though it will do what you want.
 
Old 08-16-2006, 11:44 AM   #6
onebuck
Moderator
 
Registered: Jan 2005
Location: Central Florida 20 minutes from Disney World
Distribution: SlackwareŽ
Posts: 13,925
Blog Entries: 44

Rep: Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159
Quote:
Originally Posted by helptonewbie
anybody have any ideas?
Hi,

You could look at alien's script

Should give you an idea on what is needed. You will have to adapt to your distro.
 
Old 08-17-2006, 05:24 AM   #7
helptonewbie
Member
 
Registered: Aug 2006
Location: England Somewhere
Distribution: Mandriva, PCLinuxOS, Karoshi, Suse, Redhat, Ubuntu
Posts: 518

Original Poster
Rep: Reputation: 39
thanks people but i've found its just as easy if not easier well simple anyway but possibly long winded but good for what i want to just re-write the file, i.e different sets of conditions lead to a different way the file gets re-written.

i.e
Code:
echo DEVICE=eth0 > /etc/sysconfig/network-scripts/ifcfg-eth0
echo BROADCAST=255.255.255.0 >> /etc/sysconfig/network-scripts/ifcfg-eth0

# and so on for the network, then:

echo HOSTNAME=$SERVER > /etc/sysconfig/network
echo NETWORKING=yes >> /etc/sysconfig/network
echo GATEWAY=$GATESETIP >> /etc/sysconfig/network

# and so on again, then:
/etc/init.d/network restart

# to restart the network and the network card with the new settings
Thanks to all that tried to help me with this matter
 
  


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
How to detect network card from the console? rollo SUSE / openSUSE 3 11-10-2005 03:16 PM
not sure how to configure my network and sound card violentpatrick Linux - Newbie 1 06-27-2004 03:09 AM
Configure network card aroop Linux - Networking 1 06-10-2004 04:28 AM
How to configure my network card on RH9 Agent007 Linux - Networking 0 11-19-2003 01:25 AM
How to configure a Network everywhere fast network card under Linux Mandrake 7.2 margo256 Linux - Newbie 1 03-12-2001 10:45 AM

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

All times are GMT -5. The time now is 07:08 PM.

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