Using the Terminal in Ubuntu Server
A graphical User Interface(GUI) makes it easy for us to navigate and do work especially in the Ubuntu desktop version. The Ubuntu server version is a lightweight copy of the deskop version, you do most of your work from the command line terminal making it a daunting task if you are not too familiar with the commands to use.
In this article, I will be going through the steps involved after installing a server version in a server in the office. From mounting a flash drive to statically assigning an address to the network interface is what will be shown.
Using lsblk to determine the location of the flash-drive after it is plugged into the usb port.
lsblk
sdc-----sdc1 is the 64GB flash that is plugged in, take note that your result will not include the "part /media/flash_drive" since I mounted the drive earlier, it is showing the mount location.
Next, create a new directory in the specified location and mount the drive using the above location.
mkdir -p /media/flash_drive
mount /dev/sdc1 /media/flash_drive
What I needed in the flash was a bash script to configure the network interface. Doing a ls-lah /media/flash_drive reveals the script file.
The content of the static_ip.sh script is what is show below and the comments show what is accomplished in each step.
#!/bin/bash
# Variables - Replace with your own values
INTERFACE="enp1s0" # Network interface
STATIC_IP="192.168.32.23" # Desired static IP address
GATEWAY="192.168.32.10" # Default gateway
DNS1="8.8.8.8" # Primary DNS
DNS2="4.4.4.4" # Secondary DNS
# Backup the current Netplan configuration
NETPLAN_CONFIG="/etc/netplan/00-installer-config.yaml"
BACKUP_CONFIG="/etc/netplan/00-installer-config.yaml.bak"
echo "Backing up current Netplan configuration to $BACKUP_CONFIG"
cp $NETPLAN_CONFIG $BACKUP_CONFIG
# Create a new Netplan configuration
echo "Creating new Netplan configuration for static IP setup"
cat <<EOF > $NETPLAN_CONFIG
network:
ethernets:
$INTERFACE:
dhcp4: no
addresses:
- $STATIC_IP/24
gateway4: $GATEWAY
nameservers:
addresses:
- $DNS1
- $DNS2
version: 2
EOF
# Apply the new Netplan configuration
echo "Applying new Netplan configuration"
netplan apply
echo "Static IP setup complete. Please check your network settings."
Executing the script.
sh /media/flash_drive/static_ip.sh ##OR
bash /media/flash_drive/static_ip.sh
A successful execution of the script creates a file "/etc/netplan/00-installer-config.yaml" , enabling the the server to be connected to the network.
And there it is, we have successfully connected a machine to the network working purely in the terminal.
领英推荐
ICT Lab Manager at Surveying and Land Studies Dept(UNITECH)
8 个月If your internet access is from behind a web proxy server use the export command, export http_proxy=https://username:password@proxy_address:port export https_proxy=https://username:password@proxy_address:port
ICT Lab Manager at Surveying and Land Studies Dept(UNITECH)
8 个月Use timeshift to make a snap shot of the state of the OS in a clean state, meaning without issues, this will serve as the restore point if after an intstallation, you find that the OS misbehaves. timeshift --create --comments "A working state" --tags D timeshift --restore ##to restore that backup state or snapshot.
ICT Lab Manager at Surveying and Land Studies Dept(UNITECH)
8 个月For doing edits in config files, use the vi text editor.