Advertisement
mysteriousdarren

Static IP

May 4th, 2011
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. You’ll need to edit the following file:
  2.  
  3. /etc/network/interfaces
  4.  
  5. Initially, the file only contains information about your local loopback address:
  6.  
  7. auto lo
  8. iface lo inet loopback
  9.  
  10. To assign a static IP address, you’ll need to make some changes to this file.
  11.  
  12. Let’s say you want to assign a static IP of 192.168.1.2 to your eth0 network connection (the first Ethernet adapter on your system; if you only have one, it will be eth0), with a subnet mask of 255.255.255.0 and a local gateway of 192.168.1.1. First, make a backup copy of the interfaces file:
  13.  
  14. sudo cp /etc/network/interfaces ~
  15.  
  16. This will make a backup copy in your home directory in case something goes amiss during the editing process. Next, fire up a text editor:
  17.  
  18. sudo vi /etc/network/interfaces
  19.  
  20. (Obviously you can substitue emacs or your editor of choice.)
  21.  
  22. Once the file is open, add the following lines:
  23.  
  24. iface eth0 inet static
  25. address 192.168.1.2
  26. netmask 255.255.252.0
  27. gateway 192.168.1.1
  28.  
  29. Once you’ve added these lines, save the interfaces file to disk, and exit your text editor. If you want to add a static DNS server, you’ll need to edit the /etc/resolv.conf file with this command:
  30.  
  31. sudo vi /etc/resolv.conf
  32.  
  33. To set a static DNS server with the address of 192.168.1.10, add this line to the file:
  34.  
  35. nameserver 192.168.1.10
  36.  
  37. Save the file, and exit your text editor.
  38.  
  39. You’ll then to need have your system load the new IP configuration. You can do that by rebooting, but if that takes too long, you can use this command to force Ubuntu to re-read the configuration files:
  40.  
  41. sudo ifup eth0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement