Basic methods of modifying IP address, gateway and DNS under Linux system

Time:2020-10-25

Temporary modification of IP address, gateway, host name and DNS will take effect immediately without restart (invalid after restart)

1. Modify the host name

Copy code

The code is as follows:

#hostname Slyar

2. Modify the IP address (eth0 is the name of the network card)

Copy code

The code is as follows:

#ifconfig eth0 192.168.1.5 netmask 255.255.255.0

3. Modify the default gateway (eth0 is the name of the network card)

Copy code

The code is as follows:

#route add default gw 192.168.1.1 dev eth0

4. Modify DNS

Copy code

The code is as follows:

#vim /etc/resolv.conf

CentOS (RedHat) command line permanently modifies IP address, gateway and DNS

The command line permanently modifies IP addresses, gateways, and DNS

1. Modify IP address
First, check the number and name of your host network card. The relevant information is under / etc / sysconfig / network scripts /.
2015123115346488.png (403×49)

As can be seen from the figure, I have two network cards. The first one is the Ethernet physical network card with the number of 0. If you have multiple network cards, the numbers are 0, 1, 2, 3…; the second network card is a loopback network card, which generally does not need to be set.

Use VIM to edit the network card that you need to set IP. Here, I can only modify ifcfg-eth0. Look at the figure and do not explain. The previous state is the writing method when bootproto is set to DHCP.

Copy code

The code is as follows:

vim /etc/sysconfig/network-scripts/ifcfg-eth0

2015123115409786.png (431×274)

Copy code

The code is as follows:

Device = eth0 ා network card name
Bootproto = static ා the way to obtain IP (static / DHCP / BOOTP), not explained
Hwaddr = 00:0c: 29:b5:b2:69 MAC address
IPADDR = 12.168.1.5 ᦇ IP address
Netmask = 255.255.255.0 ᦇ subnet mask
Network = 192.168.1.0 ᦇ network address
Broadcast = 192.168.0.255 ᦇ broadcast address
Nboot = yes ා start device

2. Modify the gateway

Copy code

The code is as follows:

vim /etc/sysconfig/network

Add a gateway message

Copy code

The code is as follows:

GATEWAY=192.168.1.1

2015123115426895.png (342×161)

3. Modify DNS

Copy code

The code is as follows:

vim /etc/resolv.conf

Add DNS information

Copy code

The code is as follows:

nameserver 192.168.1.1

2015123115443346.png (294×160)

4. Reload the network configuration

Copy code

The code is as follows:

/etc/init.d/network restart

2015123115500158.png (543×113)

Recommended Today

VBS version of decryption base64 encryption script

Copy codeThe code is as follows: Function fDecode(sStringToDecode)  ‘This function will decode a Base64 encoded string and returns the decoded string.  ‘This becomes usefull when attempting to hide passwords from prying eyes.  Const CharList = “ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/”  Dim iDataLength, sOutputString, iGroupInitialCharacter  sStringToDecode = Replace(Replace(Replace(sStringToDecode, vbCrLf, “”), vbTab, “”), ” “, “”)  iDataLength = Len(sStringToDecode)  If iDataLength Mod 4 <> 0 Then  fDecode = “Bad string passed to fDecode() function.”  Exit Function  End If  For iGroupInitialCharacter = 1 To iDataLength Step 4  Dim iDataByteCount, iCharacterCounter, sCharacter, iData, iGroup, sPreliminaryOutString  iDataByteCount = 3  iGroup = 0     For iCharacterCounter = 0 To 3      sCharacter = Mid(sStringToDecode, iGroupInitialCharacter + iCharacterCounter, 1)       If sCharacter = “=” Then        iDataByteCount = iDataByteCount – 1        iData = 0       Else        iData = InStr(1, CharList, sCharacter, 0) – 1         If iData = -1 Then          fDecode = “Bad string passed to fDecode() function.”          Exit Function         End If       End If      iGroup = 64 * iGroup + iData     Next  iGroup = Hex(iGroup)  iGroup = String(6 – Len(iGroup), “0”) & iGroup  sPreliminaryOutString = Chr(CByte(“&H” & Mid(iGroup, 1, 2))) & Chr(CByte(“&H” & Mid(iGroup, 3, 2))) & Chr(CByte(“&H” & Mid(iGroup, 5, 2)))  sOutputString = sOutputString & Left(sPreliminaryOutString, iDataByteCount)  Next  fDecode = sOutputString  End Function VBS code package