Add network configuration file for DHCP or static IPs by running the following commands respectively:
For DHCP:
#!/bin/bash # This line specifies the interpreter to be used for executing the script
# This script adds a network configuration file for DHCP or static IPs
# For DHCP:
echo "network:" > /etc/netplan/00-installer-config.yaml # Creates a new network configuration file and adds the "network:" header
echo " version: 2" >> /etc/netplan/00-installer-config.yaml # Adds the version number to the network configuration file
echo " ethernets:" >> /etc/netplan/00-installer-config.yaml # Adds the "ethernets:" section to the network configuration file
echo " eth0:" >> /etc/netplan/00-installer-config.yaml # Adds the "eth0:" interface to the network configuration file
echo " dhcp4: true" >> /etc/netplan/00-installer-config.yaml # Enables DHCP for the "eth0" interface
netplan apply # Applies the changes made to the network configuration file
# For static IPs:
# echo "network:" > /etc/netplan/00-installer-config.yaml # Creates a new network configuration file and adds the "network:" header
# echo " version: 2" >> /etc/netplan/00-installer-config.yaml # Adds the version number to the network configuration file
# echo " ethernets:" >> /etc/netplan/00-installer-config.yaml # Adds the "ethernets:" section to the network configuration file
# echo " eth0:" >> /etc/netplan/00-installer-config.yaml # Adds the "eth0:" interface to the network configuration file
# echo " addresses: [192.168.1.100/24]" >> /etc/netplan/00-installer-config.yaml # Sets a static IP address for the "eth0" interface
# echo " gateway4: 192.168.1.1" >> /etc/netplan/00-installer-config.yaml # Sets the gateway for the "eth0" interface
# netplan apply # Applies the changes made to the network configuration file
For static IPs:
#!/bin/bash
# This script is used to configure a static IP address for the eth0 interface in the netplan configuration file.
# First, we need to add the necessary lines to the netplan configuration file.
# The "echo" command is used to print the specified text to the standard output.
# The ">>" operator is used to append the output to the specified file.
# The "-e" option is used to enable interpretation of backslash escapes.
# The "-n" option is used to suppress the trailing newline.
# The "auto eth0" line specifies that the eth0 interface should be automatically configured on boot.
echo -e "auto eth0" >> /etc/netplan/00-installer-config.yaml
# The "iface eth0 inet static" line specifies that the eth0 interface should use a static IP address.
echo -e "iface eth0 inet static" >> /etc/netplan/00-installer-config.yaml
# The "address 192.168.1.100" line specifies the static IP address to be assigned to the eth0 interface.
echo -e "address 192.168.1.100" >> /etc/netplan/00-installer-config.yaml
# The "gateway 192.168.1.1" line specifies the default gateway for the eth0 interface.
echo -e "gateway 192.168.1.1" >> /etc/netplan/00-installer-config.yaml
# The "nameservers" line specifies the DNS nameservers to be used.
echo -e "nameservers" >> /etc/netplan/00-installer-config.yaml
# The "addresses [8.8.8.8, 8.8.4.4]" line specifies the IP addresses of the DNS nameservers.
echo -e "addresses [8.8.8.8, 8.8.4.4]" >> /etc/netplan/00-installer-config.yaml
# Once the necessary lines have been added to the netplan configuration file, we need to apply the changes.
# The "netplan apply" command is used to apply the changes made to the netplan configuration file.
netplan apply
3. Adjust network proxy settings by editing `bash.bashrc` and `apt.conf` files:
For bash.bashrc file, run the following command in terminal:
# This script is used to adjust network proxy settings by editing the bash.bashrc and apt.conf files.
# The following command is used to add the http_proxy environment variable to the bash.bashrc file, which specifies the proxy server and port to be used for HTTP connections.
echo "export http_proxy=http://your-proxy-ip:port" >> ~/.bashrc
# The following command is used to add the https_proxy environment variable to the bash.bashrc file, which specifies the proxy server and port to be used for HTTPS connections. The value is set to the same as the http_proxy variable.
echo "export https_proxy=$http_proxy" >> ~/.bashrc
# The following command is used to add the ftp_proxy environment variable to the bash.bashrc file, which specifies the proxy server and port to be used for FTP connections. The value is set to the same as the http_proxy variable.
echo "export ftp_proxy=$http_proxy" >> ~/.bashrc
# The following command is used to add the no_proxy environment variable to the bash.bashrc file, which specifies a list of hosts or domains that should not be accessed through the proxy. In this case, localhost and 127.0.0.1 are excluded.
echo "export no_proxy='localhost, 127.0.0.1'" >> ~/.bashrc
# The source command is used to reload the bash.bashrc file, so the changes made to the file can take effect in the current session.
source ~/.bashrc
4. To enable root login for SSH, edit `sshd_config` file:
Run the following command in terminal to open sshd_config file using Nano editor:
# This script is used to enable root login for SSH by editing the sshd_config file using the Nano editor.
# The following command uses sudo to run the Nano editor and open the sshd_config file located in the /etc/ssh directory.
sudo nano /etc/ssh/sshd_config
# The following line is used to enable root login by changing the value of PermitRootLogin from "no" to "yes".
PermitRootLogin yes
# The following line is used to save the changes made in the sshd_config file.
Ctrl+O
# The following line is used to exit the Nano editor.
Ctrl+X
# The following line is used to restart the SSH service to apply the changes made in the sshd_config file.
sudo service ssh restart
5. Find and replace “PermitRootLogin no” with “yes” on the line that says ‘PermitRootLogin no’ in sshd_config file using Ctrl + W (Windows) or Cmd + F (Mac).