Source: https://www.youtube.com/watch?v=Wvf0mBNGjXY
$ echo $SHELL
>> shellvar
$ pwd
>> /home/my_dir1
$ cd new_dir; mkdir www; pwd
>> /home/new_dir/
$ mkdir -p /tmp/asia/india/bangalore
$ rm -r /tmp/my_dir1
$ cp -r my_dir1 /tmp/my_dir1
# Add text to a file. Ctrl+D to save and exit
$ cat > new_file.txt
# view contents of a file
$ cat new_file.txt
$ whoami
>> matthew
$ id
>> uid=1001(matthew) gid=1001(matthew) groups=1001(matthew)
$ su aparna
>> Password:
$ ssh [email protected]
# download file
$ curl https://example.com/text.txt -O
$ wget https://example.com/text.txt -O file.txt
# view os data
ls /etc/*release*
cat /etc/*release*
yum repolist
yum list ansible
yum remove ansible
yum --showduplicates list anisble
service httpd start
systemctl start httpd
systemctl stop httpd
systemctl status httpd
systemctl enable httpd
systemctl disable httpd
# Create a system file that runs on $ systemctl start my_app
cd /etc/systemd/system
touch my_app.service
my_app.service
[Unit]
Description=My python web application
[Service]
ExecStart=/usr/bin/python3 /opt/code/my_app.py
ExecStartPre=/opt/code/configure_db.sh
ExecStartPost=/opt/code/email_status.sh
Restart=always
[Install]
WantedBy=multi-user.target
$ systemctl daemon-reload
$ systemctl start my_app
$ systemctl stop my_app
$ systemctl enable my_app
Vi
$ vi index.html
esc - command mode i - insert mode KHJL - up, down, left, right delete - x delete whole line - dd copy - yy paste - p scroll - ctrl+up / ctrl+down : - command :w - save :q - quit :wq - save and quit / - find (/of), n to move to next word
$ ip addr show
$ ssh [email protected]
Network Address Translation (NAT)
Helps you instantiate many VMs with code
- Works for virtualbox, vmware, hyper-v, docker
$ vagrant init centos/7
$ ls
$ vagrant up
$ vagrant ssh
Vagrantfile
Vagrant.configure("2") do |config|
config.vm.box = "centos/7"
config.vm.network "forwarded_port", guest: 80, host: 8080
config.vm.synced_folder "../data", "/vagrant_data"
config.vm.provider "virtualbox" do |vb|
vb.memory = "1024"
end
config.vm.provision "shell", inline: <<-SHELL
apt-get update
apt-get install -y apache2
SHELL
end
$ ping db
$ cat >> /etc/hosts
192.168.1.11 db
192.168.1.11 www.google.com
$ ping db
Configure it centrally in a DNS resolver server
- 8.8.8.8 by google points to many popular sites
$ cat /etc/resolv.conf
nameserver 192.168.1.100
search mycompany.com prod.mycompany.com
Forward All to 8.8.8.8
Record Types A - web-server - 192.168.1.1 AAAA - web-server - 2001:0db8:85a3:0000:0000:8a2e:0370:7334 CNAME - food.web-server - eat.web-server, hungry.web-server
Nig doesn't look at etc/resolv file
nslookup www.google.com
dig www.google.com
- Network switch connects multiple devices
- Router connects multiple network switches
ip link
ip addr add 192.168.1.10/24 dev eth0
ip addr add 192.168.1.11/24 dev eth0
route
ip route add 192.168.2.0/24 via 192.168.1.1
Allowing packets to be sent back from another device
$ cat /proc/sys/net/ipv4/ip_forward
>> 0
$ echo 1 > /proc/sys/net/ipv4/ip_forward
1
Must change in in /etc/sysctl.conf to persist b/w reboots
net.ipv4.ip_forward = 1
Lookback address
- localhost is 127.0.0.1 means myself
ip addr show
YAML Key value pair
Fruit: Apple
Vegetable: Carrot
Liquid: Water
Array/Lists
Fruits:
- Orange
- Apple
- Banana
Dictionary/Map
Banana:
Calories: 105
Fat: 0.4 g
Carbs: 27 g