Static IP on LAN

Discuss Applications
Post Reply
User avatar
Calum
guru
guru
Posts: 1349
Joined: Fri Jan 10, 2003 11:32 am
Location: Bonny Scotland
Contact:

Static IP on LAN

Post by Calum »

hello,
i have two machines, harvey and claudia, they both get switched on and off a lot and both have resultantly got different IP addresses on the LAN whenever they boot up. i am a little bit over guessing the IP when i ssh from one to the other, so i want to give them both static IP addresses. is this easy and how is it done?

i am thinking it involves editing /etc/hosts and will be googling based on this assumption in a minute, but thought i might as well ask here too. also, will it in any way mess up the 3 *NT machines also connected to this network, so log as i use IPs that don't tend to get handed out?

thanks etc...

Tux
guru
guru
Posts: 689
Joined: Wed Jan 08, 2003 10:40 am

Post by Tux »

If you're in slack just run netconfig, but you havn't specified a distro so I dunno.

User avatar
Calum
guru
guru
Posts: 1349
Joined: Fri Jan 10, 2003 11:32 am
Location: Bonny Scotland
Contact:

Post by Calum »

sorry man! damn!

right well harvey runs red hat and claudia runs debian sarge.
and really what i want is to be able to use ssh and samba without having to guess what IP the machine is on after every bootup, meaning for example that i could type "ssh claudia" instead of for instance "ssh 192.168.0.103" after a couple of tries.

i did quickly google but it looks a bit more involved than i had initially thought. hmmm.

User avatar
Void Main
Site Admin
Site Admin
Posts: 5716
Joined: Wed Jan 08, 2003 5:24 am
Location: Tuxville, USA
Contact:

Post by Void Main »

First you have to determine what IP addresses you can use, what the proper NETMASK is for your netork, and what your GATEWAY address is. In addition you'll need to know what your DNS servers are, but this is probably already set correctly from your DHCP setup. There are many ways for you to determine all of this information but here is one way: On your redhat box look in the /var/lib/dhcp directory where you should find a file called "dhclient-eth0.leases" assuming your ethernet interface name is "eth0". In that file you should find your currently assigned IP address, your NETMASK and your GATEWAY (would be in the "routers" line). Let's say you determine your current DHCP assigned settings are:

IP Address: 192.168.1.199
GATEWAY: 192.168.1.1
NETMASK: 255.255.255.0

Now, your DHCP server assigns you an address from a range of addresses. If your router assigns your addresses you'll have to look at it to determine what the DHCP range is that it gives out addresses from. Now, pick an IP address that is outside of that range (so your DHCP server can't assingn an address to someone else that will conflict with you).

Say the DHCP server range is 192.168.1.100 through 192.168.1.200 then you could pick an address from 192.168.1.201 through 192.168.1.254 or 192.168.1.2 through 192.168.1.99 (your router is using 192.168.1.1 and you don't want to use the same address). Say you decide to assign 192.168.1.210 and 192.168.1.211 to your two Linux machines. Ping those addresses before assigning them to make sure you don't have anything else on those addresses. Ok, now on your Red Hat box you can use the graphical tool "redhat-config-network". Click on your "eth0" and click the "edit" button. Now click the "static" radio button and put in "192.168.1.210" for the IP address, 255.255.255.0 for the subnet mask, and 192.168.1.1 for the gateway address. That's it (you might need to click "deactivate" and then "activate" for it to set the address immediately). You can now check it with "ifconfig" and verify the address is assigned to your interface and do a "netstat -rn" to verify the gateway setting is correct. Everything should work just as it did when you had a DHCP assigned address.

Now on the Debian box I'll have to go from memory since I don't have a machine up at home right now with Debian, but I do have one at work. I believe the file you need to change is /etc/network/interfaces. You should have an entry for "eth0" and it will have the keyword "dhcp" next to it. You have to change that to "static". You also have to put your gateway, netmask and ip address information right below that. Sort of like this:

http://documents.made-it.com/Debian_Int ... ver-5.html

I believe your interfaces file would look something like this:

Code: Select all

iface eth0 inet static
        address 192.168.1.211
        netmask 255.255.255.0
        broadcast 192.168.1.255
        gateway 192.168.1.1
If you have trouble with it, paste in a copy of your interfaces file in a working dhcp configuration and I can tell you what you need. At any rate, once you get the addresses assigned you can edit the /etc/hosts file on both machines and put entries for them like this:

192.168.1.210 redhathostname.calumshouse.com redhathostname
192.168.1.211 debianhostname.calumshouse.com debianhostname

Of course if you were running a Linux DHCP server and dynamic DNS setup the DNS names would be configured automatically and you could continue to use DHCP. But you would need a dedicated machine to stay up all the time (probably an old junker without a monitor you would just leave under a desk somewhere and forget about).

User avatar
Calum
guru
guru
Posts: 1349
Joined: Fri Jan 10, 2003 11:32 am
Location: Bonny Scotland
Contact:

Post by Calum »

well, it's a d-link wireless router. it works, but it has only a web browser interface so no linux.

interestingly we have such a headless junker under our living room table, it makes a hell of a racket and it breaks my heart that our flatmates got it as a resource server (the only machine always on on the network with 120GB of storage on it) and they just installed windows NT on it. i tried i really did, but some people are simply lazy.

and thanks very much indeed for that void main, i have applied the changes you suggest no bother at all and i suppose i will see how i go. i am sure everything will be fine.

Post Reply