Linux网络连接模式以及修改静态IP
来源:互联网 发布:virtualbox nat网络 编辑:程序博客网 时间:2024/05/19 13:27
- 网络连接模式
1、桥接模式
centos相当于一台物理机,可以直接连接外网,能够连接同一个局域网下为桥接模式的其他宿主机上的客户机
2、NAT模式
通过宿主机连接外网,可以访问同一个局域网的其他物理主机,但是其他主机不能够访问该宿主机
3、only host
不能连接外网,可以连接同一宿主机的其他客户机
- 修改静态IP
[root@localhost network-scripts]# cd /etc/sysconfig/network-scripts/[root@localhost network-scripts]# lsifcfg-eno16777736 ifdown-ipv6 ifdown-TeamPort ifup-ippp ifup-routes network-functionsifcfg-lo ifdown-isdn ifdown-tunnel ifup-ipv6 ifup-sit network-functions-ipv6ifdown ifdown-post ifup ifup-isdn ifup-Teamifdown-bnep ifdown-ppp ifup-aliases ifup-plip ifup-TeamPortifdown-eth ifdown-routes ifup-bnep ifup-plusb ifup-tunnelifdown-ib ifdown-sit ifup-eth ifup-post ifup-wirelessifdown-ippp ifdown-Team ifup-ib ifup-ppp init.ipv6-global[root@localhost network-scripts]# cp ifcfg-eno16777736 ifcfg-eno16777736.bak[root@localhost network-scripts]# lsifcfg-eno16777736 ifdown-ippp ifdown-Team ifup-ib ifup-ppp init.ipv6-globalifcfg-eno16777736.bak ifdown-ipv6 ifdown-TeamPort ifup-ippp ifup-routes network-functionsifcfg-lo ifdown-isdn ifdown-tunnel ifup-ipv6 ifup-sit network-functions-ipv6ifdown ifdown-post ifup ifup-isdn ifup-Teamifdown-bnep ifdown-ppp ifup-aliases ifup-plip ifup-TeamPortifdown-eth ifdown-routes ifup-bnep ifup-plusb ifup-tunnelifdown-ib ifdown-sit ifup-eth ifup-post ifup-wireless[root@localhost network-scripts]# nano ifcfg-eno16777736.bak
TYPE=EthernetBOOTPROTO=noneDEFROUTE=yesIPV4_FAILURE_FATAL=noIPV6INIT=noIPV6_AUTOCONF=noIPV6_DEFROUTE=noIPV6_FAILURE_FATAL=noNAME=eno16777736UUID=89b859f5-ddf6-4056-a99c-c29fbf5d4ee2DEVICE=eno16777736ONBOOT=yesPEERDNS=yesPEERROUTES=yesIPV6_PEERDNS=noIPV6_PEERROUTES=noIPADDR=192.168.109.100PREFIX=24GATEWAY=192.168.109.2DNS=192.168.109.2
[root@localhost network-scripts]# cd /etc[root@localhost etc]# ls |grep resolv.confresolv.conf[root@localhost etc]# nano resolv.conf[root@localhost etc]#
nameserver 192.168.109.2重启网络service network restart
- 查看所有进程信息
[root@localhost ~]# ps -Af |grep servicecr121 1794 1 0 05:29 ? 00:00:00 /usr/libexec/goa-identity-servicecr121 1985 1494 0 05:29 ? 00:00:00 /usr/bin/gnome-software --gapplication-servicecr121 2029 1 0 05:29 ? 00:00:00 /usr/libexec/dconf-serviceroot 2332 2179 0 05:39 pts/0 00:00:00 grep --color=auto service[root@localhost ~]#
- top:动态显示进程的信息包括CPU,内存的使用情况
- cut剪切显示
[root@localhost aa]# cat a.txthellohow are you[root@localhost aa]# cut -c 1-7 a.txt//显示1-7列hellohow are[root@localhost aa]#
[root@localhost aa]# ps -Af |cut -c 45-80 |more//查看所有进程,并剪切显示45-80列
- sudo 临时使用root的权利,命令执行完毕失效
给用户添加sudo的权利
- 查看磁盘分区
[root@localhost dev]# fdisk -l /dev/sdaDisk /dev/sda: 21.5 GB, 21474836480 bytes, 41943040 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk label type: dosDisk identifier: 0x000bcae1 Device Boot Start End Blocks Id System/dev/sda1 * 2048 616447 307200 83 Linux/dev/sda2 616448 4810751 2097152 82 Linux swap / Solaris/dev/sda3 4810752 41943039 18566144 83 Linux[root@localhost dev]#
- 查看磁盘使用情况
[root@localhost ~]# df -ah .Filesystem Size Used Avail Use% Mounted on/dev/sda3 18G 11G 7.5G 58% /[root@localhost ~]#
- 输出指定目录的上级目录
[root@localhost ~]# dirname /a/b/c/a/b[root@localhost ~]#
- 取出当前目录的名称
[root@localhost ~]# basename /a/b/cc[root@localhost ~]#
- 修改主机名称
[root@localhost etc]# ls -l |grep hostdrwxr-xr-x. 3 root root 17 Sep 6 10:22 ghostscript-rw-r--r--. 1 root root 9 Jun 7 2013 host.conf-rw-r--r--. 1 root root 22 Nov 23 20:23 hostname-rw-r--r--. 1 root root 158 Jun 7 2013 hosts-rw-r--r--. 1 root root 370 Jun 7 2013 hosts.allow-rw-r--r--. 1 root root 460 Jun 7 2013 hosts.deny[root@localhost etc]# nano hostname[root@localhost etc]# cat hostnames128[root@localhost etc]
- 设置主机名与IP地址的映射
[root@s128 etc]# ls -l|grep hostsdrwxr-xr-x. 3 root root 17 Sep 6 10:22 ghostscript-rw-r--r--. 1 root root 158 Jun 7 2013 hosts-rw-r--r--. 1 root root 370 Jun 7 2013 hosts.allow-rw-r--r--. 1 root root 460 Jun 7 2013 hosts.deny[root@s128 etc]# nano hosts[root@s128 etc]# ping s128PING s128 (192.168.109.128) 56(84) bytes of data.64 bytes from s128 (192.168.109.128): icmp_seq=1 ttl=64 time=0.028 ms64 bytes from s128 (192.168.109.128): icmp_seq=2 ttl=64 time=0.030 ms64 bytes from s128 (192.168.109.128): icmp_seq=3 ttl=64 time=0.030 ms64 bytes from s128 (192.168.109.128): icmp_seq=4 ttl=64 time=0.034 ms64 bytes from s128 (192.168.109.128): icmp_seq=5 ttl=64 time=0.032 ms64 bytes from s128 (192.168.109.128): icmp_seq=6 ttl=64 time=0.034 ms64 bytes from s128 (192.168.109.128): icmp_seq=7 ttl=64 time=0.031 ms64 bytes from s128 (192.168.109.128): icmp_seq=8 ttl=64 time=0.029 ms^C
- 命令的嵌套
[root@s128 ~]# echo s128>a.txt[root@s128 ~]# cat a.txts128[root@s128 ~]# ping $(cat a.txt)PING s128 (192.168.109.128) 56(84) bytes of data.64 bytes from s128 (192.168.109.128): icmp_seq=1 ttl=64 time=0.044 ms64 bytes from s128 (192.168.109.128): icmp_seq=2 ttl=64 time=0.089 ms64 bytes from s128 (192.168.109.128): icmp_seq=3 ttl=64 time=0.052 ms^C--- s128 ping statistics ---3 packets transmitted, 3 received, 0% packet loss, time 1999msrtt min/avg/max/mdev = 0.044/0.061/0.089/0.021 ms[root@s128 ~]# ping `cat a.txt`PING s128 (192.168.109.128) 56(84) bytes of data.64 bytes from s128 (192.168.109.128): icmp_seq=1 ttl=64 time=0.056 ms64 bytes from s128 (192.168.109.128): icmp_seq=2 ttl=64 time=0.069 ms64 bytes from s128 (192.168.109.128): icmp_seq=3 ttl=64 time=0.036 ms^C--- s128 ping statistics ---3 packets transmitted, 3 received, 0% packet loss, time 2000msrtt min/avg/max/mdev = 0.036/0.053/0.069/0.016 ms[root@s128 ~]#
- 添加用户
[root@s128 sbin]# useradd -m centos2[root@s128 sbin]# cd /home[root@s128 home]# lscentos2 cr121 hadoop test.txt[root@s128 home]# su centos2[centos2@s128 home]$
- 删除用户
[centos2@s128 home]$ su rootPassword:[root@s128 home]# which userdel/usr/sbin/userdel[root@s128 home]# man userdel[root@s128 home]# userdel -rf centos2userdel: user centos2 is currently used by process 2484[root@s128 home]# lscr121 hadoop test.txt[root@s128 home]
- 查看文件的物理位置(由于存在符号链接的作用,显示的是逻辑位置)
[root@s128 home]# cd /bin[root@s128 bin]# pwd/bin[root@s128 bin]# pwd -P/usr/bin[root@s128 bin]#
- 访问环境变量
[root@s128 ~]# echo $PATH/root/.bashrc/anaconda3/bin:/usr/local/maven352/bin:/root/anaconda3/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/usr/local/spark2.2/bin:/usr/local/spark2.2/sbin:/usr/local/jdk1.8/bin:/root/bin[root@s128 ~]# echo ${PATH}/root/.bashrc/anaconda3/bin:/usr/local/maven352/bin:/root/anaconda3/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/usr/local/spark2.2/bin:/usr/local/spark2.2/sbin:/usr/local/jdk1.8/bin:/root/bin[root@s128 ~]# echo "PATH"
- 定义环境变量export,只在session中有效
[root@s128 ~]# export name=jj[root@s128 ~]# namebash: name: command not found...[root@s128 ~]# echo $namejj[root@s128 ~]#
- export三元运算符
[root@s128 ~]# export name=yy[root@s128 ~]# echo $nameyy[root@s128 ~]# export mypath=${name:-$PATH}[root@s128 ~]# echo mypathmypath[root@s128 ~]# echo $mypathyy[root@s128 ~]# export mypath=${name1:-$PATH}[root@s128 ~]# echo $mypath/root/.bashrc/anaconda3/bin:/usr/local/maven352/bin:/root/anaconda3/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/usr/local/spark2.2/bin:/usr/local/spark2.2/sbin:/usr/local/jdk1.8/bin:/root/bin[root@s128 ~]#
- 查看最后一次命令执行成功与否 0:成功 1:失败
[root@s128 ~]# lsaa anaconda-ks.cfg Desktop Downloads Pictures Templates Videosanaconda3 a.txt Documents Music Public test.txt[root@s128 ~]# rm -rf aa[root@s128 ~]# echo $?0[root@s128 ~]#
- 获取参数的个数
[root@s128 ~]# nano a.sh[root@s128 ~]# ./a.sh 12 3 4helloworld[root@s128 ~]# lltotal 20drwxr-xr-x. 22 root root 4096 Nov 29 01:48 anaconda3-rw-------. 1 root root 2741 Nov 23 20:24 anaconda-ks.cfg-rwxr--r--. 1 root root 52 Dec 19 01:03 a.shdrwxr-xr-x. 2 root root 6 Nov 29 00:47 Desktopdrwxr-xr-x. 2 root root 6 Nov 29 00:47 Documentsdrwxr-xr-x. 2 root root 6 Nov 29 00:47 Downloadsdrwxr-xr-x. 2 root root 6 Nov 29 00:47 Musicdrwxr-xr-x. 2 root root 6 Nov 29 00:47 Picturesdrwxr-xr-x. 2 root root 6 Nov 29 00:47 Publicdrwxr-xr-x. 2 root root 6 Nov 29 00:47 Templates-rw-r--r--. 1 root root 27 Dec 16 17:48 test.txt-rw-r--r--. 1 root root 2 Dec 19 01:06 t.txtdrwxr-xr-x. 2 root root 6 Nov 29 00:47 Videos[root@s128 ~]# cat t.txt3
- 获取参数的总个数 $# 参数左移 shift 获取脚本名称:$0
[root@s128 ~]# ./a.sh 1 2 3 4helloworldthe parameters is: num=4the script's name is :./a.sh./a.sh: line 6: echon: command not found22[root@s128 ~]#
- if
[root@s128 ~]# help ifif: if COMMANDS; then COMMANDS; [ elif COMMANDS; then COMMANDS; ]... [ else COMMANDS; ] fi
- for循环
利用for循环输出0-100
for循环遍历
[root@s128 bin]# for x in a b c ;do echo $x;doneabc[root@s128 bin]#
阅读全文
0 0
- Linux网络连接模式以及修改静态IP
- 【Linux 网络】虚拟机静态IP NAT连接外部网络(局域网以及广域网)
- Linux修改静态IP
- linux修改静态ip
- linux修改静态ip方法&&如何使用xshell连接
- LINUX 下的静态IP配置无法连接网络
- Linux修改IP为静态
- 更改静态ip导致无法连接网络
- 【Linux 网络】虚拟机动态IP NAT连接外部网络(局域网以及广域网)
- 在windows下用XShell 连接虚拟机linux Ubuntu14,以及静态ip,DNS设置
- linux中 centos 7 rhel7下 vm虚拟机怎么设置静态ip 开机自动连接网络
- Linux静态IP设置--修改配置文件
- SuSE Linux 修改静态IP地址
- linux静态ip修改-基础知识(1)
- linux 静态与动态修改IP地址
- Linux 修改静态ip后无法上网
- 修改linux(centos7)操作系统静态ip
- CentOS设置静态IP,以及解决设置静态IP过程中,修改DNS配置后重启网络nameserver被删除的问题
- 快速删除从CSDN复制的代码行前的数字的方法
- IT行业的风险投资
- static 关键字
- 让sublime等同web storm
- 设计模式C++实现(13)——中介者模式
- Linux网络连接模式以及修改静态IP
- leetcode 70. Climbing Stairs爬梯子(DP问题)
- 小班研讨课的感想
- isEqual
- 编辑距离问题
- 2015年蓝桥杯JavaB组表格计算
- C# Linq查询的基本练习
- Python基础学习(3)
- C#事件学习