Ubuntu 命令合集

系统优化

关闭防火墙
ufw disable 
防火墙在系统启动时自动禁用

网络调试

##ubuntu 

//方法一、network命令

# service network restart

或者

/etc/init.d/networking restart

//方法二、ifdown/ifup命令

# ifdown eth0 关闭

# ifup eth0 开启

//方法三、ifconfig命令

# ifconfig eth0 down 关闭

# ifconfig eth0 up 开启


一、网卡地址配置
Ubuntu的网络配置文件是:/etc/network/interfaces
1、以DHCP 方式配置网卡
   auto eth0
   iface eth0 inet dhcp
用sudo /etc/init.d/networking restart命令使网络设置生效

2、为网卡配置静态IP地址
sudo vi /etc/network/interfaces
auto eth0
iface eth0 inet static
address 192.168.1.100
netmask 255.255.255.0
gateway 192.168.1.1
sudo /etc/init.d/networking restart

3、设定第二个IP地址(虚拟IP地址)
sudo vi /etc/network/interfaces
auto eth0:1
iface eth0:1 inet static
address 192.168.1.101
netmask 255.255.0
gateway 192.168.1.1
sudo /etc/init.d/networking restart

4、设置主机名称(hostname)
使用下面的命令来查看当前主机的主机名称:
  sudo /bin/hostname
使用下面的命令来设置当前的主机名称:
  sudo /bin/hostname newname

5、配置DNS
   (1) /etc/hosts中加入一些主机名称和这些主机名称对应的IP地址,这是本机的静态查询
   (2) /etc/resolv.conf 
       nameserver *.*.*.*

设置DNS
不能直接修改 vim /etc/resolv.conf    




ssh 服务

apt install openssh-server
systemctl status ssh


1 新用户登录后 使用sudo passwd root 更改root密码

永久修改root密码
sudo passwd root

说明
PermitRootLogin prohibit-password 允许root秘钥远程登录,但是禁止root远程密码登录
PermitRootLogin yes 允许root远程登录,密码秘钥皆可
PasswordAuthentication yes 允许ssh密码登录权限

打开ssh的配置文件 vi /etc/ssh/sshd_config  
PermitRootLogin without-password 默认注释,在这行下添加 
PermitRootLogin yes
PasswordAuthentication yes  修改成yes
systemctl  restart ssh
重启ssh服务

Ubuntu的镜像源 更新

添加Ubuntu的镜像源
lsb_release -a
查看系统的版本
根据阿里云的镜像地址
https://developer.aliyun.com/mirror/ubuntu?spm=a2c6h.13651102.0.0.12c21b11nziP2u


  
2、更新Ubuntu的镜像源
  (1)需要查看Ubuntu的版本号 lsb_release -a

  (2)镜像文件 vi /etc/apt/sources.list
    
    阿里镜像地址 https://developer.aliyun.com/mirror/ubuntu?spm=a2c6h.13651102.0.0.12c21b11n6tMgJ

        ubuntu 18.04(bionic)

        ubuntu 20.04(focal)

  (4) apt-get update 更新源

更新源
apt update  更新本地软件仓库的索引
apt upgrade  日常升级 → 安全、保守

apt install update:将远程软件库和本地软件库做对比,检查哪些软件可以更新,以及软件包依赖关系,给出一个分析报告。只检查不更新。
apt install full-upgrade:在执行full-upgrade 之前也要先执行update ,升级整个系统,必要时可以移除旧软件包

apt install dist-upgrade:

在执行dist-upgrade 之前也要先执行update ,dist-upgrade 包含upgrade,同时增添了以下功能:
可以智能处理新软件包的依赖
智能冲突解决系统
安装新软件包时,可以移除旧软件包,但不是所有软件都可以。


简单下载包
apt install -y tree nmap sysstat lrzsz  telnet   vim  lsof  net-tools rsync ntpdate   unzip wget

posted @ 2022-03-28 16:26  mmszxc  阅读(90)  评论(0)    收藏  举报