Linux - NetworkingThis forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
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
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.
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
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.