Jul 08

How to Configure Network Settings in CentOS 7

1 – FIND YOUR NETWORK ADAPTER

Once logged in, you’ll want to enable and configure your network adapter.  First, you’ll need to get the name of your network adapter(s) by running the following command:

nmcli d

Below you’ll see my results of running this command.  My results show I have an Ethernet adaptor called ens160 and it’s currently disabled.  Please take note of the name of your network adapter, which may be different.

"nmcli d" Results

2 – CONFIGURE NETWORK ADAPTOR

Once you have the name of your network adapter, you’ll want to enable it and configure it.  We will configure it using the vi text editor.  If you’re not familiar with vi, take a look at:

vi cheat sheet

Use the following command to use vi to configure your network settings.  Note: replace ens160 with the name of your network adapter you noted above)

vi /etc/sysconfig/network-scripts/ifcfg-ens160

The content will look something like this:

TYPE=Ethernet
BOOTPROTO=dhcp
DEFROUTE=yes
PEERDNS=yes
PEERROUTES=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes
IPV6_FAILURE_FATAL=no
NAME=ens160
UUID=7f1aff2d-b154-4436-9497-e3a4dedddcef
DEVICE=ens160
ONBOOT=no

To Configure a DHCP IP

Modify the following lines:

BOOTPROTO=dhcp
ONBOOT=yes

To Configure a Static IP

Modify the following line:

BOOTPROTO=static

Add the following lines and replace them with the static IP settings you need.  Note: DOMAIN is the default DNS Search domain and it’s optional to add that line.

IPADDR=192.168.2.11
NETMASK=255.255.255.0
GATEWAY=192.168.2.1
DNS1=8.8.8.8
DNS2=8.8.4.4
DOMAIN=sigkillit.com

3 – CONFIGURE HOST NAME (Optional)

Optionally, you can use vi to configure the host name and default search domain by running:

vi /etc/hostname

Modify the following line:

HOSTNAME=server.sigkillit.com

4 – RESTART NETWORK SERVICE

To apply your new network settings run the following command to restart the network service

systemctl restart network

 

Jan 01

GenerateIPv4Addresses.vbs

'=========================================================================
' GenerateIPv4Addresses.vbs
' VERSION: 1.0
' AUTHOR: Brian Steinmeyer
' EMAIL: sigkill@sigkillit.com
' WEB: http://sigkillit.com
' DATE: 1/1/2011
' COMMENTS: Input the Start IPv4 IP Address and the End IPv4 IP Address to
' Generate All IP Addresses In a Log File for the Given Range.
' EXAMPLE: Input the Starting IPv4 Address:    192.168.1.1
'          Input the Ending IPv4 Address: 192.168.1.255
'=========================================================================
Option Explicit

' Generate IPv4 Addresses
Dim ipStart: ipStart = InputBox("Input the Starting IPv4 Address")
Dim ipEnd: ipEnd = InputBox("Input the Ending IPv4 Address")
Call Logger("GenerateIPv4Addresses.txt", GenerateIPv4Addresses(ipStart, ipEnd), True)
Wscript.Echo "Finished"

Private Function GenerateIPv4Addresses(ipStart, ipEnd)

On Error Resume Next

' Validate IPv4 Address
Dim strResult: strResult = ""
If ValidateIPv4(ipStart) = False OR ValidateIPv4(ipEnd) = False Then
strResult = "Invalid IP Range: " & ipStart & " - " & ipEnd
Else
' Generate IP Range
Dim ipOctetStart: ipOctetStart = Split(ipStart,".")
Dim ipOctetEnd: ipOctetEnd = Split(ipEnd,".")
Dim i, oct1,oct2,oct3,oct4, blnInitial: blnInitial = True
For oct1 = ipOctetStart(0) to ipOctetEnd(0)
For oct2 = ipOctetStart(1) to ipOctetEnd(1)
For oct3 = ipOctetStart(2) to ipOctetEnd(2)
If blnInitial = True Then
blnInitial = False
If StrComp(oct1, ipOctetEnd(0)) = 0 AND StrComp(oct2, ipOctetEnd(1)) = 0 AND StrComp(oct3, ipOctetEnd(2)) = 0 Then
' Initial Loop on Octet4 is the Final Loop
For oct4 = ipOctetStart(3) to ipOctetEnd(3)
strResult = strResult & oct1 & "." & oct2 & "." & oct3 & "." & oct4 & vbCrLf
Next
Else
' Initial Loop on Octet4 is Not the Final Loop
For oct4 = ipOctetStart(3) to 255
strResult = strResult & oct1 & "." & oct2 & "." & oct3 & "." & oct4 & vbCrLf
Next
End If
Else
If StrComp(oct1, ipOctetEnd(0)) = 0 AND StrComp(oct2, ipOctetEnd(1)) = 0 AND StrComp(oct3, ipOctetEnd(2)) = 0 Then
' Non-Initial Loop is the Final Loop
For oct4 = 0 to ipOctetEnd(3)
strResult = strResult & oct1 & "." & oct2 & "." & oct3 & "." & oct4 & vbCrLf
Next
Else
' Non-Initial Loop is Not the Final Loop
For oct4 = 0 to 255
strResult = strResult & oct1 & "." & oct2 & "." & oct3 & "." & oct4 & vbCrLf
Next
End If
End If
Next
Next
Next
End If

' Return Results
GenerateIPv4Addresses = strResult

On Error Goto 0

End Function

Private Function ValidateIPv4(ip)

On Error Resume Next

' Validate IPv4 Address
Dim blnValid: blnValid = True
Dim arrIP: arrIP = Split(ip,".")
If UBound(arrIP) = 3 Then
Dim i
For i = LBound(arrIP) to UBound(arrIP)
If IsNumeric(arrIP(i)) = True Then
If arrIP(i) > 255 Then
blnValid = False
End If
Else
blnValid = False
End If
Next
Else
blnValid = False
End If

' Check For Errors
If Err.Number <> 0 Then
blnValid = False
Err.Clear
End If

' Return Result
If blnValid = True Then
ValidateIPv4 = True
Else
ValidateIPv4 = False
End If

On Error Goto 0

End Function

Private Sub Logger(fileName, logMessage, blnNewLog)

On Error Resume Next

Const ForReading = 1, ForWriting = 2, ForAppending = 8
Dim objFSO: Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim scriptPath: scriptPath = Left(WScript.ScriptFullName,InstrRev(WScript.ScriptFullName,"\"))
Dim logName
If InStr(1,fileName,"\",1) > 0 Then
logName = fileName
If objFSO.DriveExists(objFSO.GetDriveName(logName)) Then
If StrComp(objFSO.GetExtensionName(logName), "", 1) = 0 Then
If Not objFSO.FolderExists(logName) Then
If objFSO.FolderExists(objFSO.GetParentFolderName(logName)) Then
objFSO.CreateFolder logName 'Create Folder In Current Path
Exit Sub
Else
Call Logger(objFSO.GetParentFolderName(logName), logMessage, blnNewLog) 'Recurse Creating Parent Folder
Call Logger(logName, logMessage, blnNewLog) 'Recurse Creating Current Folder
Exit Sub
End If
End If
Else
If Not objFSO.FileExists(logName) Then
If Not objFSO.FolderExists(objFSO.GetParentFolderName(logName)) Then
Call Logger(objFSO.GetParentFolderName(logName), logMessage, blnNewLog)  'Recurse Creating Parent Folder
Call Logger(logName, logMessage, blnNewLog)  'Recurse Creating Current Folder
End If
End If
End If
End If
Else
logName = scriptPath & fileName
End If
Dim logFile
If blnNewLog = True Then
Set logFile = objFSO.CreateTextFile(logName, True)
Else
If objFSO.FileExists(logName) Then
Set logFile = objFSO.OpenTextFile(logName, ForAppending, True)
Else
Set logFile = objFSO.CreateTextFile(logName, True)
End If
End If
logFile.WriteLine logMessage
logFile.Close
Set objFSO = Nothing

On Error Goto 0

End Sub