常用的Linux命令

# 配置国内的镜像源:
## centos
cp -a /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak
wget -O /etc/yum.repos.d/CentOS-Base.repo https://repo.huaweicloud.com/repository/conf/CentOS-7-reg.repo
yum clean all
yum makecache
## ubuntu
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
sudo echo /
'deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse' > /etc/apt/sources.list
sudo apt-get update
sudo apt-get upgrade

# 配置静态ip:
cat > /etc/sysconfig/network-scripts/ifcfg-enp0s8 << EOF
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=static
IPADDR=192.168.56.107
NETMASK=255.255.255.0
NM_CONTROLLED=no
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=enp0s8
UUID=54975d97-a7d9-4168-852a-9a82d514faed
DEVICE=enp0s8
ONBOOT=yes
EOF
systemctl restart network

hostnamectl set-hostname k8s-master # 永久设置主机名
dhclient # 请求dhcp自动分配ip
sed -ri 's/.*swap.*/#&/' /etc/fstab # 永久关闭swap
swapoff -a  # 临时

# 关闭防火墙相关操作
systemctl stop firewalld
systemctl disable firewalld
sed -i 's/enforcing/disabled/' /etc/selinux/config
setenforce 0  # 临时关闭selinux

# 将桥接的IPv4流量传递到iptables的链
cat > /etc/sysctl.d/k8s.conf << EOF
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
sysctl --system  # 生效

# 时间同步
yum install ntpdate -y
ntpdate time.windows.com

# 安装docker
## centos
wget https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo -O /etc/yum.repos.d/docker-ce.repo
yum -y install docker-ce-18.06.1.ce-3.el7
systemctl enable docker && systemctl start docker
# 添加docker国内的源
cat > /etc/docker/daemon.json << EOF
{
  "registry-mirrors": ["https://b9pmyelo.mirror.aliyuncs.com"]
}
EOF
# 添加k8s国内的源
cat > /etc/yum.repos.d/kubernetes.repo << EOF
[kubernetes]
name=Kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=0
repo_gpgcheck=0
gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
EOF
##ubuntu
curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun # 安装docker
sudo apt-get remove docker docker-engine docker.io containerd runc # 缷载docker

# 查看历史命令
history
history > history.txt
cat ~/.bash_history
ctrl + r # 搜索历史命令

echo -n MTIzNDU2 | base64 --decode # 对base64加密的数据进行解密
echo -n 123456 | base64 # 对明文数据进行base64加密

brctl show # 查看主机上的网桥
ip r # 查看host上的路由表
ping -c 3 ip_address # 指定发送ping包的数量
sysctl net.ipv4.ip_forward # 查看ip forwarding的情况
sysctl -w net.ipv4.ip_forward=1 # 启用ip_forward
iptables-save # 查看iptables的规则
iptables -t nat -S # 查看nat表的iptables规则 
tcpdump -i docker0 -n icmp # 抓取经过docker0的icmp包流量
systemctl daemon-reload
systemctl restart docker.service # 重启docker daemon
ip netns # 查看主机上的网络名称空间
ip netns exec ns_name brctl show # 查看网络名称空间中的设备情况
ip link set enp0s9 promisc on # 打开网卡的混杂模式
ip link show enp0s9 # 查看网卡的信息
ifup eth2.10
ifup eth2.20 # 启用sub-interface
ifconfig eth2.10 172.16.10.1 netmask 255.255.255.0 up
ifconfig eth2.20 172.16.20.1 netmask 255.255.255.0 up # 将网关Ip配置到sub-interface
traceroute ip # 看到此ip所经过的路由情况
原文地址:https://www.cnblogs.com/Richardo-M-Q/p/14109932.html