http://codesnippets.joyent.com/posts/show/319
First, backup your "/etc/network/interfaces" file. I'll be doing everything in the command line interface (CLI) AKA the Terminal.
This copies and renames the interfaces file so that you have a backup:
Code:
sudo cp /etc/network/interfaces /etc/network/interfaces_old
If you screw up the new interfaces file you can replace it with the backup with the following code:
Code:
sudo cp /etc/network/interfaces_old /etc/network/interfaces
This opens up a basic text editor. When you're done editing code press "Control + X". That should bring up if you want to save it, press Y, then press ENTER (we don't want to change the name), and nano should exit.
Code:
sudo nano /etc/network/interfaces
You will probably have this at the end of the interfaces file.
Code:
# The primary network interface
auto eth0
iface eth0 inet dhcp
Basically this means that eth0 (Your first ethernet port) is setup as DHCP. You want to change from your DHCP address to a static IP. To do that you will need to change a few things. Below is an example. (Do not use this example because your setup is probably different).
Code:
# The primary network interface
auto eth0
iface eth0 inet static
address 192.168.0.100
netmask 255.255.255.0
network 192.168.0.0
broadcast 192.168.0.255
gateway 192.168.0.1
On the 3rd line we changed "dhcp" to "static" and then added some other information. The "address" is the IP you want for your machine. The next line has "netmask", this should be if you're on a local LAN "255.255.255.0", just like in the example. The "network" is a little tricky. In you post you said "192.168.1.150", here for the network you would want "192.168.1.0". This has to deal with the netmask (go look up subnetting if you want more info on that, it's beyond the scope of this post). The "broadcast" for your "192.168.1.150" IP would be "192.168.1.255", again another subnetting thing. The "gateway" is your router. You MUST know this or you won't get any internet at all. Your gateway should be "192.168.1.1".
If you do not know your gateway, install "traceroute" and do a trace on a website.
Traceroute install:
Code:
sudo apt-get install traceroute
Then run traceroute. You will get something that looks like this:
Code:
user@ubuntu:~$ traceroute google.com
traceroute to google.com (209.85.171.99), 30 hops max, 40 byte packets
1 MyHomeNetworkSSID (192.168.1.1) 1.425 ms 1.835 ms 2.317 ms
This tells me that my first hop hits a router. That router happens to be my gateway. It also displays the IP address of your gateway. In my case that is "192.168.1.1".
All in all, if you want your 192.168.1.150 IP, your config should look like this:
Code:
# The primary network interface
auto eth0
iface eth0 inet static
address 192.168.1.150
netmask 255.255.255.0
network 192.168.1.0
broadcast 192.168.1.255
gateway 192.168.1.1
If this does not answer your question, we probably will need to know your gateway's IP and the IP you want to use. And if you really screwed up we will need to see your interfaces file.
I probably wrote way too much.
Bookmarks