Setting a Static IP Address in Linux
Example with Netplan (Ubuntu):
1. Identify the Current Network Interface
Run:
ip a
Note the name of your interface (e.g., eth0, ens33).
2. Edit the Network Configuration
Open the configuration file in a text editor (e.g., nano):
sudo vim /etc/netplan/01-netcfg.yaml
3. Configure the Static IP
Add or modify the configuration (replace with your own values):
network:
version: 2
ethernets:
eth0:
addresses:
- 192.168.1.100/24
gateway4: 192.168.1.1
nameservers:
addresses: [8.8.8.8, 8.8.4.4]
You can also use a bash script to set a static IP:
ip.sh
4. Apply the Changes
Apply the changes:
Run:
sudo netplan apply
5. Verify the Connection
Make sure the IP address has changed:
ip a
Check internet connectivity:
ping google.com
Notes:
- The configuration file path may vary depending on the distribution.
- For
NetworkManager, usenmclior the graphical interface.
🚀 Explore more guides on our blog 👉 blog.1it.pro
📧 Contact us: admin@1it.pro for expert IT guidance.
🌐 Explore more: Visit 1it.pro for top-tier IT solutions.