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.
Is there some way I can use my ip address in a bash program. My ip address changes, as I am conencted to a DHCP cable modem. I wish to write a script that uses the ip address in it, but i can not just put xxx.xxx.xxx.xxx because the x's change when I restart the computer. I also need to know how to designate wich network card im using because the comp has two net cards.
is there a command like +eth0ip or +eth1ip that i can substitute for [ip of eth0] or [ip of eth1]
i have just tested it (haven't done it while writing it) and it works fine.
type it in a shell and then do an "echo eth0".
It will show you the ip-address of the interface eth0!
step by step:
with "eth0=...." you define a variable (your current ip-address). You can call it also ipaddress or something else.
"ifconfig eth0" will get all infos of the interface eth0 (or eth1 eth2 ...). These infos are piped " | " to "grep". grep cuts out the "inet addr"-part from the ifconfig-command.
This part is then handed over to "awk" who is responsible for sorting out the second part (..print $2) of the the grep results. this will result in something like "...addr:192.168.xxx.xxx:".
You can't work with this, so this part is piped to "sed".
sed now is doing some filtering and the result is the pure ip-address of the interface you want to know!
i don't know that half-life game, but if you start it with "hlds_run", you can now just add the name of the vairable (eth0 or ipaddress or whatever you've called it).
Have you done shell-scripting before or do you want to start it by hand?
btw: i think you can't copy and paste the command-line i have written because the shell might interpret the pipe-sign ( | ) al the letter "l". And that will never work ;-)
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.