Query IP subnet mask DNS gateway and set fixed IP when Linux automatically obtains IP

 

1: Query IP and subnet mask when Linux automatically obtains IP

Open a command terminal and type ifconfig -a


As can be seen from the above figure: IP: 10.113.1.130, Mask: 255.255.255.0

 

Two: View the gateway

Type in the command terminal: route



The default line 10.113.0.254 is the default gateway 

 

Three: View the default DNS service

Enter in the command terminal: cat /etc/resolv.conf



 

behind the nameserver is DNS

 

Four: Set a fixed IP address

In practical applications, the server generally uses a fixed IP address.

In the above example, you already know the IP, gateway, subnet mask and DNS of the machine, and now you can set your own fixed IP.

1. Enter the command terminal and enter: vi /etc/sysconfig/network-scripts/ifcfg-eth0

Note: ifcfg-eth0 is its own corresponding network card address. If there is a network card, this is the address.

2. Press i key to enter edit mode

 

Modify the configuration as follows:

DEVICE=eth0
BOOTPROTO=static
HWADDR=00:0C:29:DF:95:82
IPV6INIT=no
NM_CONTROLLED=yes
ONBOOT=yes#boot start
TYPE=Ethernet
IPADDR=10.113.1.130#own IP address
NETMASK=255.255.255.0#subnet mask
GATEWAY=10.113.0.254#gateway
DNS1=202.96.209.133
UUID=92405d80-c79f-4c32-b23b-098c6bb357d3

 

 3. Exit and save. Press Esc, then enter

:wq

 

4. Remember to restart the network card service.

 

service network restart

 

 

 

Five: Modify whether to use the graphical interface or the text interface to boot.

Personally recommend using the text interface. There are also more text interfaces in the formal environment.

vi /etc/inittab

 Enter text editing mode, press i key to enter editing mode

Edit the text as follows:

# Default runlevel. The runlevels used are:
#   0 - halt (Do NOT set initdefault to this)
#   1 - Single user mode
#   2 - Multiuser, without NFS (The same as 3, if you do not have networking)
#   3 - Full multiuser mode
#   4 - unused
#   5 - X11
#   6 - reboot (Do NOT set initdefault to this)
#
id:3:initdefault:

 按Esc键,然后退出并保存

:wq

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326361508&siteId=291194637