How to modify the IP address and gateway of ubuntu

Source: Internet
Author: User
Tags nameserver

1. Use commands to set the Ubuntu IP Address

1. modify the configuration file blacklist. conf to disable IPv6.

Sudo VI/etc/modprobe. d/blacklist. conf

The contents of the blacklist. conf file in The modprobe. D folder in the ETC folder are edited using the VI Editor (or other editors such as gedit.

Note: it can only be modified in root user mode.

Add blacklist IPV6 at the end of this document

View the Modification result.

CAT/etc/modprobe. d/blacklist. conf

2. Set the IP address and subnet mask of the eth0 Nic

Sudo ifconfig eth0 192.168.2.1 netmask 255.255.255.0

Change the IP address to 192.168.2.1 and the subnet mask to 255.255.255.0.

3. Set the gateway for Ubuntu IPaddress

Sudo route add default GW 192.168.2.254

4. Modify/etc/resolv. conf for the Ubuntu ipserver DNS, and add nameserver DNS address 1 and nameserver DNS address 2 to it.

5. Restart the network service (if not, restart Ubuntu: sudo reboot)

Sudo/etc/init. d/networking restart

6. view the current IP Address

Ifconfig

2. directly modify the Ubuntu IP system configuration file

The network configuration file of the Ubuntu IP address is in the root directory:/etc/Network/interfaces

Note:: After modifying the content in the interfaces document, you need to modify the managed parameter in the/etc/NetworkManager. conf document to make it true and restart. Otherwise, the system will prompt "the wired network device is not hosted ".

After it is enabled, you can set DHCP or manually set static IP addresses.

Auto eth0 indicates that eth0 is automatically mounted to the NIC when it is started.

1. Configure the NIC in DHCP Mode

Edit file/etc/Network/interfaces

Sudo VI/etc/Network/interfaces

Replace eth0 with the following rows:

# The primary network interface-use DHCP to find our address

Auto eth0

Iface eth0 Inet DHCP

Run the following command to make the network settings take effect:

Sudo/etc/init. d/networking restart

You can also enter the following command in the command line to obtain the sudo dhclient eth0 address.

2. configure a static Ubuntu IP address for the NIC

Edit file/etc/Network/interfaces

Sudo VI/etc/Network/interfaces

Replace eth0 with the following rows:

# The primary network interface  

auto eth0  

iface eth0 inet static  

address 192.168.2.1  

gateway 192.168.2.254  

netmask 255.255.255.0  

#network 192.168.2.0  

#broadcast 192.168.2.255 

After you change the IP Address allocation mode of eth0 to static, you can specify the IP address, gateway, subnet mask, and other information for it.

Replace the above Ubuntu IP address and other information with your own.

Run the following command to make the network settings take effect:

Sudo/Etc/init. d/networkingRestart

3. Set the second Ubuntu IP address (virtual IP address)

Edit the file/etc/Network/interfaces:

SudoVI/Etc/Network/interfaces

Add the following lines to the file:

auto eth0:1  

iface eth0:1 inet static  

address x.x.x.x  

netmask x.x.x.x  

network x.x.x.x  

broadcast x.x.x.x  

gateway x.x.x.x 

Fill in all information such as address, netmask, network, broadcast, and gateways according to your situation;

Run the following command to make the network settings take effect:

Sudo/etc/init. d/networking restart

4. Set Host Name (hostname)

Run the following command to view the Host Name of the current host: sudo/bin/hostname

Run the following command to set the Host Name of the current host: sudo/bin/hostname newname

When the system starts, it reads the host name from/bin/hostname.

5. Configure DNS

First, you can add some host names to/etc/hosts and the IP addresses corresponding to these host names. This is a simple static query on the local machine. To access the DNS server for query, you need to set the/etc/resolv. conf file. If the IP address of the DNS server is 192.168.2.2, the content of the/etc/resolv. conf file should be:

Search chotim.com

Nameserver 192.168.2.2

6. Manually restart the network service: sudo/etc/init. d/networking restart

The returned results are as follows:

* Reconfiguring network interfaces... [OK]

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.