Temporary Network Configuration Guideline (Linux)


This guideline describes how to set up a temporary network configuration on a Linux server using ip
commands. These changes will only persist until the next reboot.
1. Identify Your Network Interface
Check available network interfaces and note the one you want to configure (e.g., ens3
).
ip link show
2. Flush Existing IP Addresses
Remove all current IP addresses from your interface to avoid conflicts.
sudo ip addr flush dev ens3
Replace
ens3
with your actual interface name.
3. Assign a New IP Address
Set the desired IP address and subnet mask.
sudo ip addr add 51.1.1.51/24 dev ens3
51.1.1.51
is the new IP./24
is the subnet mask (255.255.255.0).
4. Bring the Interface Up
Activate the interface if it is down.
sudo ip link set ens3 up
5. Set Up Routing
a. Add a Static Route (Optional)
If you need to reach a specific host directly:
sudo ip route add 15.2.2.15 dev ens3
b. Set the Default Gateway
Direct all traffic through the gateway:
sudo ip route add default via 15.2.2.15
6. Configure DNS
Set a DNS server to resolve domain names.
echo "nameserver 8.8.8.8" | sudo tee /etc/resolv.conf
This replaces your
/etc/resolv.conf
with Google’s DNS.
Note: Changes to/etc/resolv.conf
are also temporary and may be overwritten by network managers.
7. Automatic Setup Script
You can use the following shell script to automate this temporary network setup.
This script will prompt you for the required details and apply the configuration.
#!/bin/bash
# Temporary Linux Network Configuration (Interactive Script)
echo "=== Temporary Network Configuration ==="
# Prompt for network interface
read -p "Enter the network interface name (e.g., ens3): " IFACE
# Prompt for new IP address (with CIDR)
read -p "Enter the new IP address with CIDR (e.g., 192.168.1.100/24): " IPADDR
# Prompt for Gateway
read -p "Enter the gateway IP address (e.g., 192.168.1.1): " GATEWAY
# Prompt for DNS
read -p "Enter the DNS server IP (e.g., 8.8.8.8): " DNS
echo ""
echo "Applying network changes..."
# Flush existing IP addresses
sudo ip addr flush dev "$IFACE"
# Assign new IP address
sudo ip addr add "$IPADDR" dev "$IFACE"
# Bring the interface up
sudo ip link set "$IFACE" up
# Add default gateway
sudo ip route add default via "$GATEWAY"
# Set DNS server
echo "nameserver $DNS" | sudo tee /etc/resolv.conf
echo ""
echo "Network configuration applied (temporarily, until reboot)."
echo "Current network status:"
ip addr show "$IFACE"
ip route
echo ""
echo "Test connectivity (ping DNS server):"
ping -c 4 "$DNS"
echo ""
echo "Done."
Usage:
Save as
network_setup_
prompt.sh
.Make executable:
chmod +x network_setup_
prompt.sh
Run:
./network_setup_
prompt.sh
Follow prompts to input interface, IP address, gateway, and DNS.
Note:
This configuration is temporary and will be lost after a reboot. For permanent changes, edit your network configuration files.
8. Verify Configuration
a. Check IP Address
ip a
b. Check Routing Table
ip route
c. Test Connectivity
Ping gateway or external IP:
ping -c 4 8.8.8.8
Test DNS:
ping -c 4 google.com
9. (Optional) Install Open vSwitch
If you need Open vSwitch for virtual networking:
sudo apt update
sudo apt install openvswitch-switch
10. Notes
Temporary: These changes will be lost after a reboot. For permanent changes, edit your network configuration files (e.g.,
/etc/network/interfaces
, Netplan, or NetworkManager settings).Permissions: All commands require root privileges (
sudo
).Interface Name: Replace
ens3
with your actual interface name.
11. Troubleshooting
If network is not working, check:
IP address assignment:
ip a
Routing table:
ip route
DNS settings:
cat /etc/resolv.conf
Interface status:
ip link show ens3
Re-run commands if you made a mistake or want to reset.
Subscribe to my newsletter
Read articles from KUMAR BISHOJIT directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
