User Tools

Site Tools


changeubuntuserverfromdhcptoastaticipaddress

This is an old revision of the document!


Change Ubuntu Server from DHCP to a Static IP Address

<p>If the Ubuntu Server installer has set your server to use DHCP, you will want to change it to a static IP address so that people can actually use it.</p> <p>Changing this setting without a GUI will require some text editing, but that's classic linux, right?</p> <p>Let's open up the /etc/network/interfaces file. I'm going to use nano, but you can choose a different editor</p>

<blockquote><p>sudo nano /etc/network/interfaces</p> </blockquote> <p>For the primary interface, which is usually eth0, you will see these lines:</p> <blockquote><p>auto eth0 iface eth0 inet dhcp</p> </blockquote> <p>As you can see, it's using DHCP right now. We are going to change dhcp to static, and then there are a number of options that should be added below it. Obviously you'd customize this to your network.</p> <blockquote><p>auto eth0 iface eth0 inet static &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; address 192.168.1.100 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; netmask 255.255.255.0 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; network 192.168.1.0 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; broadcast 192.168.1.255 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; gateway 192.168.1.1</p>

</blockquote> <p> Now we'll need to add in the DNS settings by editing the resolv.conf file:</p> <blockquote><p>sudo nano /etc/resolv.conf</p></blockquote> <p>On the line 'nameserver xxx.xxx.xxx.xxx' replace the x with the IP of your name server. (You can do ifconfig /all to find out what they are) </p> <p>You need to also remove the dhcp client for this to stick (thanks to Peter for noticing). You might need to remove dhcp-client3 instead.</p> <p> </p> <blockquote> sudo apt-get remove dhcp-client<br /> OR_<br /> sudo apt-get remove isc-dhcp-client </blockquote> <p>Now we'll just need to restart the networking components:</p> <blockquote><p>sudo /etc/init.d/networking restart</p> </blockquote> <p>Ping www.google.com. If you get a response, name resolution is working(unless of course if google is in your hosts file).</p> ===== Promiscuous Mode ===== To temporarily do this run:<br /> ifconfig eth1 promisc If you want to make it permanent, edit /etc/network/interfaces <file> auto eth1 iface eth1 inet manual up ifconfig $IFACE 0.0.0.0 up up ip link set $IFACE promisc on down ip link set $IFACE promisc off down ifconfig $IFACE down </file> ===== References ===== * http://manpages.ubuntu.com/manpages/lucid/man5/interfaces.5.html * https://help.ubuntu.com/10.04/serverguide/network-configuration.html * http://ubuntuforums.org/showthread.php?t''1225099 – Main.FredPettis - 16 Mar 2010

changeubuntuserverfromdhcptoastaticipaddress.1359347354.txt.gz · Last modified: 2013/07/05 19:06 (external edit)