Techridez
VirtualizationLinuxWindowsNetworking
  • Techridez Knowledge base
  • Techridez guide
  • Tech Scale
    • Measurements
  • Techridez Knowledge Base
  • Bacis
    • Protocol and Port Numbers
  • Windows Customization
    • Capture Wim image from OS
  • Virtualization
    • Proxmox Command Guide
  • Windows Server Guide
    • Transfer FSMO roles
    • FSMO commands
  • DevOps
    • WebDev
      • How to install fail2ban on ubuntu server and create custom jail config.
      • MySQL Bin Files Eating Lots of Disk Space (fix)
      • Install ClamAV antivirus in Ubuntu Server and Client With Cron job
      • 404 hyperlink not working after wordpress migration
      • Apache Virtual Host Script with mysql db.
      • OsTicket
      • How to Backup MySQL Databases Automatically on Ubuntu
      • Cron Job
        • Create cron job for maldet scanning
        • Auto-Restart MySQL When It Crashes During a Brute Force Attack
        • How to change default crontab editor
        • How To Use Cron to Automate Tasks on Ubuntu 18.04
        • How To Use Cron to Automate Tasks on CentOS 8
      • Wordpress Security
      • Open database Error!: could not find driver linux Fix
    • Vagrant
    • Windows Subsystem for Linux
    • How to set static ip on ubuntu server using yaml file.
    • How to install ansible
  • Linux
    • Tools
    • How to install CrowdStrike in Linux
    • How to Install Ossec agent in linux
    • Linux Commands
    • SFTP (CrushFTP)with HA
    • 🗃️Transfer & sync files in a directory to remote node using crontab & rsync
  • Networking
    • Upgrade Cisco9200L firmware to recommended
  • Cyber Security
    • ISC² (International Information System Security Certification Consortium)
Powered by GitBook

©️ Techridez

On this page

Was this helpful?

  1. DevOps

How to set static ip on ubuntu server using yaml file.

$ cd /etc/netplan/

You need check what file you have in this directory some have 01-netcfg.yaml or 50-cloud-init.yaml that depends on you, for this tutorial i have 50-cloud-init.yaml

so type ls to find whats inside ?

$ ls
50-cloud-init.yaml 

so we have 50-cloud-init.yaml in our directory, first i will backup this file, for that you need to type following commands, if i type ls again i can see backup file and current configuration file, before that i will login as root, for that i will use sudo su

$ sudo su
$ cp 50-cloud-init.yaml 50-cloud-init.yaml.backup
$ ls 
$ 50-cloud-init.yaml 50-cloud-init.yaml.backup

now i need to edit 50-cloud-init.yaml , i will use nano to edit the file.

$ nano 50-cloud-init.yaml

this will open 50-cloud-init.yaml in nano. your ethernet adpter may vary, mine is ens160:

# This file is generated from information provided by
# the datasource.  Changes to it will not persist across an instance.
# To disable cloud-init's network configuration capabilities, write a file
# /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:
# network: {config: disabled}
#network:
#    ethernets:
#        ens160:
#            dhcp4: yes
#    version: 2
network:
  version: 2
  renderer: networkd
  ethernets:
    ens160:
     dhcp4: no
     addresses: [192.168.1.230/24]
     gateway4: 192.168.1.1
     nameservers:
       addresses: [8.8.8.8]

Now if you see above you can find i have commended default dhcp, and added my static ip, you can copy same settings and change to your settings if you want.

Now press ^x (Ctrl + x ) to exit, and save it.

sudo netplan --debug apply

$ sudo netplan --debug apply
** (generate:1962): DEBUG: 12:48:51.528: Processing input file /etc/netplan/50-cloud-init.yaml..
** (generate:1962): DEBUG: 12:48:51.529: starting new processing pass
** (generate:1962): DEBUG: 12:48:51.530: ens160: setting default backend to 1
** (generate:1962): DEBUG: 12:48:51.530: Configuration is valid
** (generate:1962): DEBUG: 12:48:51.531: Generating output files..
** (generate:1962): DEBUG: 12:48:51.532: NetworkManager: definition ens160 is not for us (backend 1)
DEBUG:netplan generated networkd configuration changed, restarting networkd
DEBUG:no netplan generated NM configuration exists
DEBUG:ens160 not found in {}
DEBUG:Merged config:
network:
  bonds: {}
  bridges: {}
  ethernets:
    ens160:
      addresses:
      - 192.168.1.230/24
      dhcp4: false
      gateway4: 192.168.1.1
      nameservers:
        addresses:
        - 8.8.8.8
  vlans: {}
  wifis: {}

DEBUG:Skipping non-physical interface: lo
DEBUG:device ens160 operstate is up, not changing
DEBUG:{}
DEBUG:netplan triggering .link rules for lo
DEBUG:netplan triggering .link rules for ens160

PreviousWindows Subsystem for LinuxNextHow to install ansible

Last updated 1 year ago

Was this helpful?