Tag: linux.tips

  • dd创建大文件制作iso启动盘

    生成一个2GB的文件
    dd if=/dev/zero of=test bs=1024k count=2048
    生成一个10GB的文件
    dd if=/dev/zero of=test bs=1024k count=10240

    dd if=/dev/zero of=test bs=8M count=128

    mac下用dd制作启动u盘

    确定盘符

    ➜  quick diskutil list

    /dev/disk0

    #:                       TYPE NAME                    SIZE       IDENTIFIER

    0:      GUID_partition_scheme                        *121.3 GB   disk0

    1:                        EFI EFI                     209.7 MB   disk0s1

    2:                  Apple_HFS mac                     120.5 GB   disk0s2

    3:                 Apple_Boot Recovery HD             650.0 MB   disk0s3

    /dev/disk1

    #:                       TYPE NAME                    SIZE       IDENTIFIER

    0:      GUID_partition_scheme                        *500.1 GB   disk1

    1:                        EFI EFI                     209.7 MB   disk1s1

    2:                  Apple_HFS 500G                    499.8 GB   disk1s2

    /dev/disk2

    #:                       TYPE NAME                    SIZE       IDENTIFIER

    0:     FDisk_partition_scheme                        *7.7 GB     disk2

    1:               Windows_NTFS 21                      7.7 GB     disk2s1

    去掉挂载

    ➜  quick diskutil umountDisk /dev/disk2

    Unmount of all volumes on disk2 was successful

    用dd写入光盘镜像

    ➜  quick sudo dd if=/Users/jpuyy/Downloads/CentOS-7.0-1406-x86_64-GnomeLive.iso of=/dev/disk2 bs=1m

  • linux设置静态ip及dns

    debian设置静态ip

    #vim /etc/network/interfaces
     auto eth0
     iface eth0 inet static
     address 219.230.144.244
     netmask 255.255.255.192
     gateway 219.230.144.254
     dns-nameservers 8.8.8.8
      重启网络服务
    /etc/init.d/networking restart

    ubuntu 20.04

    cat /etc/netplan/00-installer-config.yaml 
    # This is the network config written by 'subiquity'
    network:
      ethernets:
        enp4s0:
          dhcp4: false
          addresses:
            - 192.168.1.66/24
          gateway4: 192.168.1.1
          nameservers:
              addresses: [192.168.1.1, 223.5.5.5]
      version: 2
    
    netplan apply

    centos设置静态ip

    #vim /etc/sysconfig/network-scripts/ifcfg-eth0  有时会是ifcfg-em1

    DEVICE="eth0"
    BOOTPROTO="static"
    HWADDR="00:A5:D1:EA:23:A4"
    IPV6INIT="yes"
    MTU="1500"
    NM_CONTROLLED="yes"
    ONBOOT="yes"
    TYPE="Ethernet"
    UUID="95fd6b2b-ecfd-4cdf-9833-e3056f22d4e8"
    IPADDR=192.168.8.126
    NETMASK=255.255.255.0
    GATEWAY=192.168.8.1
    • 配置dns解析

    echo "nameserver 211.98.1.28">> /etc/resolv.conf

    弄完后,记得重启网络服务

    /etc/init.d/network restart

    查看网络ip

    ifconfig

    查看网关

    netstat -rn

    查看nameserver

    cat /etc/resolv.conf
  • 连接vps上的ssh

    创建一个权限最低的用户

    useradd -M -s /bin/false username

    创建该用户的密码:

    passwd username
    • windows使用MyenTunnel,输好用户名,密码,ip,端口

    在linux下使用密钥认证可以免输密码,而且参考使用ssh_config,创建并在~/.ssh/config里写入以下内容,参考:http://www.lainme.com/doku.php/blog/2011/01/%E4%BD%BF%E7%94%A8ssh_config

    jpuyy@ubuntu $ vim ~/.ssh/config
     Host vps
     User jpuyy
     Hostname jpuyy.com
     PreferredAuthentications publickey
     IdentityFile ~/.ssh/id_rsavps
     DynamicForward 7070

    这时在shell下使用

    $ssh vps

    更有一步登天之感。

    其他工具

    autossh可以在ssh断掉后重连

    sudo apt-get install autossh

    autossh -M 2000 -N -v  username@hostip

    plink可以直接指定密码

    ssh需要手动输入,因为把密码表现在history中相当恐怖

    sudo apt-get install putty-tools

    plink -N -v username@hostip -pw password

    sshpass也可以指定密码

    Description : Tool for non-interactively performing password authentication with
    : so called “interactive keyboard password authentication” of SSH.
    : Most users should use more secure public key authentication of SSH
    : instead.
    yum install sshpass

    mosh是在网络比较慢的时候使用,尤其是国外线路

    http://mosh.mit.edu/

  • linux几个掌握系统信息的命令

    查看CPU信息

    /proc/cpuinfo

    里面有flag信息,如果有lm,则支持64位

    系统负载命令

    uptime w htop top 都可查看
     ------------23:41:57 up 4:42, 3 users, load average: 0.00, 0.00, 0.00
     ------------当前时间 运行时间 用户数 系统负载 (最近1分钟、5分钟、15分钟系统的负载)

    查看硬盘信息命令

    fdisk -l

    JOBS使用

    # jobs 查看后台运行的进程
    # fg %n 让后台运行的进程n到前台来,再Ctrl+c即可终止该程序.
    # bg %n 让进程n到后台去;

    root@debian:~# nohup ping g.cn &
    [1] 9576
    root@debian:~# nohup: 忽略输入并把输出追加到”nohup.out”

    root@debian:~# jobs
    [1]+ Running nohup ping g.cn &

    接着执行

    root@debian:~# bg %1
    [1]+ nohup ping g.cn &
    root@debian:~# jobs
    [1]+ Running nohup ping g.cn & //变为了running

    Linux Jobs等前后台运行命令详解,停止后台程序:
    Shell支持作用控制,有以下命令:
    1. command& 让进程在后台运行 / nohup command &
    2. jobs 查看后台运行的进程
    3. fg %n 让后台运行的进程n到前台来,再Ctrl+c即可终止该程序.
    4. bg %n 让进程n到后台去;
    PS:”n”为jobs -l查看到的进程编号.

    RX 和 TX

    TX: transmit 传送. RX: receive 接收

    查看系统内核

    uname -r

    查看内核名

    uname -s
    Linux
    

    查看架构

    uname -m
    x86_64

    查看系统的字符集

    echo $LANG $LANGUAGE
    TAIL -F FILENAME

    会把filename里最尾部的内容显示在屏幕上,并且不但刷新,使你看到最新的文件内容

    查看内存使用情况

    free -m

    total used free shared buffers cached
    Mem: 7866 6213 1653 0 209 2711
    -/+ buffers/cache: 3292 4574
    Swap: 0 0 0
    真实的空余内存为4574MB

    文件系统使用情况

    df -h (有时可以看到使用率到100%,但是系统会保留5%的空间用于root用户来登陆及其他操作)

    df -T(可查看file system类型)

    df -i 查看已用和未用的inode数量及百分比

    查看模块

    lsmod

    查看UUID:

    方法一:#ls -l /dev/disk/by-uuid/
    方法二:#blkid

    LSOF命令

    先要 apt-get install lsof

    查看tcp端口应用程序#lsof -i tcp

    查看 linux 发行版,尝试以下方法

    cat /etc/redhat-release
    cat /etc/debian_version
    cat /etc/lsb-release
    cat /etc/os-release