mirror of
https://github.com/LCTT/TranslateProject.git
synced 2024-12-26 21:30:55 +08:00
Merge branch 'master' of github.com:LCTT/TranslateProject
This commit is contained in:
commit
f552369682
@ -1,8 +1,9 @@
|
||||
Linux 中的TCP/IP网络配置:net-tools vs. iproute2
|
||||
iproute2 对决 net-tools
|
||||
================================================================================
|
||||
如今很多系统管理员依然通过组合使用诸如ifconfig、route、arp和netstat等命令行工具(统称为net-tools)来配置网络功能,解决网络故障。net-tools起源于BSD的TCP/IP工具箱,后来成为老版本Linux内核中配置网络功能的工具。但自2001年起,Linux社区已经对其停止维护。同时,一些比如Arch Linux和CentOS/RHEL 7的Linux发行版则已经完全抛弃了net-tools,以支持iproute2。
|
||||
|
||||
作为网络配置工具的一份子,iproute2的出现旨在在功能上取代net-tools。net-tools通过procfs(/proc)和ioctl系统调用去访问和改变内核网络配置,而iproute2则通过netlink套接字接口与内核通讯。抛开性能而言,iproute2的用户接口比net-tools显得更加直观。比如,各种网络资源(如link、IP地址、路由和隧道等)均使用合适的对象抽象去定义,使得用户可使用一致的语法去管理不同的对象。更重要的是,到目前为止,iproute2仍处在[持续开发][1]中。
|
||||
如今很多系统管理员依然通过组合使用诸如ifconfig、route、arp和netstat等命令行工具(统称为net-tools)来配置网络功能,解决网络故障。net-tools起源于BSD的TCP/IP工具箱,后来成为老版本Linux内核中配置网络功能的工具。**但自2001年起,Linux社区已经对其停止维护。**同时,一些Linux发行版比如Arch Linux和CentOS/RHEL 7则已经完全抛弃了net-tools,只支持iproute2。
|
||||
|
||||
作为网络配置工具的一份子,iproute2的出现旨在从功能上取代net-tools。net-tools通过procfs(/proc)和ioctl系统调用去访问和改变内核网络配置,而iproute2则通过netlink套接字接口与内核通讯。抛开性能而言,iproute2的用户接口比net-tools显得更加直观。比如,各种网络资源(如link、IP地址、路由和隧道等)均使用合适的对象抽象去定义,使得用户可使用一致的语法去管理不同的对象。更重要的是,到目前为止,iproute2仍处在[持续开发][1]中。
|
||||
|
||||
如果你仍在使用net-tools,而且尤其需要跟上新版Linux内核中的最新最重要的网络特性的话,那么是时候转到iproute2的阵营了。原因就在于使用iproute2可以做很多net-tools无法做到的事情。
|
||||
|
||||
@ -27,10 +28,12 @@ Linux 中的TCP/IP网络配置:net-tools vs. iproute2
|
||||
使用这些命令来激活或停用某个指定的网络接口。
|
||||
|
||||
使用**net-tools**:
|
||||
|
||||
$ sudo ifconfig eth1 up
|
||||
$ sudo ifconfig eth1 down
|
||||
|
||||
使用**iproute2**:
|
||||
|
||||
$ sudo ip link set down eth1
|
||||
$ sudo ip link set up eth1
|
||||
|
||||
@ -39,9 +42,11 @@ Linux 中的TCP/IP网络配置:net-tools vs. iproute2
|
||||
使用这些命令配置网络接口的IPv4地址。
|
||||
|
||||
使用**net-tools**:
|
||||
|
||||
$ sudo ifconfig eth1 10.0.0.1/24
|
||||
|
||||
使用**iproute2**:
|
||||
|
||||
$ sudo ip addr add 10.0.0.1/24 dev eth1
|
||||
|
||||
值得注意的是,可以使用iproute2给同一个接口分配多个IP地址,ifconfig则无法这么做。使用ifconfig的变通方案是使用[IP别名][2]。
|
||||
@ -55,9 +60,11 @@ Linux 中的TCP/IP网络配置:net-tools vs. iproute2
|
||||
就IP地址的移除而言,除了给接口分配全0地址外,net-tools没有提供任何合适的方法来移除网络接口的IPv4地址。相反,iproute2则能很好地完全。
|
||||
|
||||
使用**net-tools**:
|
||||
|
||||
$ sudo ifconfig eth1 0
|
||||
|
||||
使用**iproute2**:
|
||||
|
||||
$ sudo ip addr del 10.0.0.1/24 dev eth1
|
||||
|
||||
### 显示网络接口的IPv4地址 ###
|
||||
@ -65,9 +72,11 @@ Linux 中的TCP/IP网络配置:net-tools vs. iproute2
|
||||
按照如下操作可查看某个指定网络接口的IPv4地址。
|
||||
|
||||
使用**net-tools**:
|
||||
|
||||
$ ifconfig eth1
|
||||
|
||||
使用**iproute2**:
|
||||
|
||||
$ ip addr show dev eth1
|
||||
|
||||
同样,如果接口分配了多个IP地址,iproute2会显示出所有地址,而net-tools只能显示一个IP地址。
|
||||
@ -79,21 +88,25 @@ Linux 中的TCP/IP网络配置:net-tools vs. iproute2
|
||||
使用这些命令为网络接口添加IPv6地址。net-tools和iproute2都允许用户为一个接口添加多个IPv6地址。
|
||||
|
||||
使用**net-tools**:
|
||||
|
||||
$ sudo ifconfig eth1 inet6 add 2002:0db5:0:f102::1/64
|
||||
$ sudo ifconfig eth1 inet6 add 2003:0db5:0:f102::1/64
|
||||
|
||||
使用**iproute2**:
|
||||
|
||||
$ sudo ip -6 addr add 2002:0db5:0:f102::1/64 dev eth1
|
||||
$ sudo ip -6 addr add 2003:0db5:0:f102::1/64 dev eth1
|
||||
|
||||
### 显示网络接口的IPv6地址 ###
|
||||
|
||||
按照如下操作可显示某个指定网络接口的IPv6地。net-tools和iproute2都可以显示出所有已分配的IPv6地址。
|
||||
按照如下操作可显示某个指定网络接口的IPv6地址。net-tools和iproute2都可以显示出所有已分配的IPv6地址。
|
||||
|
||||
使用**net-tools**:
|
||||
|
||||
$ ifconfig eth1
|
||||
|
||||
使用**iproute2**:
|
||||
|
||||
$ ip -6 addr show dev eth1
|
||||
|
||||
![](https://farm4.staticflickr.com/3906/15111848536_f6cb7ddb4f_z.jpg)
|
||||
@ -103,9 +116,11 @@ Linux 中的TCP/IP网络配置:net-tools vs. iproute2
|
||||
使用这些命令可移除接口中不必要的IPv6地址。
|
||||
|
||||
使用**net-tools**:
|
||||
|
||||
$ sudo ifconfig eth1 inet6 del 2002:0db5:0:f102::1/64
|
||||
|
||||
使用**iproute2**:
|
||||
|
||||
$ sudo ip -6 addr del 2002:0db5:0:f102::1/64 dev eth1
|
||||
|
||||
### 改变网络接口的MAC地址 ###
|
||||
@ -113,9 +128,11 @@ Linux 中的TCP/IP网络配置:net-tools vs. iproute2
|
||||
使用下面的命令可[篡改网络接口的MAC地址][3],请注意在更改MAC地址前,需要停用接口。
|
||||
|
||||
使用**net-tools**:
|
||||
|
||||
$ sudo ifconfig eth1 hw ether 08:00:27:75:2a:66
|
||||
|
||||
使用**iproute2**:
|
||||
|
||||
$ sudo ip link set dev eth1 address 08:00:27:75:2a:67
|
||||
|
||||
### 查看IP路由表 ###
|
||||
@ -123,6 +140,7 @@ Linux 中的TCP/IP网络配置:net-tools vs. iproute2
|
||||
net-tools中有两个选择来显示内核的IP路由表:route和netstat。在iproute2中,使用命令ip route。
|
||||
|
||||
使用**net-tools**:
|
||||
|
||||
$ route -n
|
||||
|
||||
----------
|
||||
@ -140,10 +158,12 @@ net-tools中有两个选择来显示内核的IP路由表:route和netstat。在
|
||||
这里的命令用来添加或修改内核IP路由表中的默认路由规则。请注意在net-tools中可通过添加新的默认路由、删除旧的默认路由来实现修改默认路由。在iproute2使用ip route命令来代替。
|
||||
|
||||
使用**net-tools**:
|
||||
|
||||
$ sudo route add default gw 192.168.1.2 eth0
|
||||
$ sudo route del default gw 192.168.1.1 eth0
|
||||
|
||||
使用**iproute2**:
|
||||
|
||||
$ sudo ip route add default via 192.168.1.2 dev eth0
|
||||
$ sudo ip route replace default via 192.168.1.2 dev eth0
|
||||
|
||||
@ -152,10 +172,12 @@ net-tools中有两个选择来显示内核的IP路由表:route和netstat。在
|
||||
使用下面命令添加或移除一个静态路由。
|
||||
|
||||
使用**net-tools**:
|
||||
|
||||
$ sudo route add -net 172.16.32.0/24 gw 192.168.1.1 dev eth0
|
||||
$ sudo route del -net 172.16.32.0/24
|
||||
|
||||
使用**iproute2**:
|
||||
|
||||
$ sudo ip route add 172.16.32.0/24 via 192.168.1.1 dev eth0
|
||||
$ sudo ip route del 172.16.32.0/24
|
||||
|
||||
@ -169,6 +191,7 @@ net-tools中有两个选择来显示内核的IP路由表:route和netstat。在
|
||||
$ netstat -l
|
||||
|
||||
使用**iproute2**:
|
||||
|
||||
$ ss
|
||||
$ ss -l
|
||||
|
||||
@ -179,6 +202,7 @@ net-tools中有两个选择来显示内核的IP路由表:route和netstat。在
|
||||
使用这些命令显示内核的ARP表。
|
||||
|
||||
使用**net-tools**:
|
||||
|
||||
$ arp -an
|
||||
|
||||
使用**iproute2**:
|
||||
@ -192,6 +216,7 @@ net-tools中有两个选择来显示内核的IP路由表:route和netstat。在
|
||||
按照如下操作在本地ARP表中添加或删除一个[静态ARP项][4]。
|
||||
|
||||
使用**net-tools**:
|
||||
|
||||
$ sudo arp -s 192.168.1.100 00:0c:29:c0:5a:ef
|
||||
$ sudo arp -d 192.168.1.100
|
||||
|
||||
@ -223,7 +248,7 @@ via: http://xmodulo.com/2014/09/linux-tcpip-networking-net-tools-iproute2.html
|
||||
|
||||
作者:[Dan Nanni][a]
|
||||
译者:[KayGuoWhu](https://github.com/KayGuoWhu)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
校对:[wxy](https://github.com/wxy)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出
|
||||
|
@ -1,3 +1,4 @@
|
||||
[KayGuoWhu translating]
|
||||
What Makes a Good Programmer?
|
||||
================================================================================
|
||||
What makes a good programmer? It’s an interesting question to ask yourself. It makes you reflect on the craft of software development. It is also a good question to ask your colleagues. It can trigger some interesting discussions on how you work together. Here are five skills I think are crucial to have in order to be a good programmer.
|
||||
|
@ -1,3 +1,4 @@
|
||||
forsil translating ...
|
||||
How to use on-screen virtual keyboard on Linux
|
||||
================================================================================
|
||||
On-screen virtual keyboard is an alternative input method that can replace a real hardware keyboard. Virtual keyboard may be a necessity in various cases. For example, your hardware keyboard is just broken; you do not have enough keyboards for extra machines; your hardware does not have an available port left to connect a keyboard; you are a disabled person with difficulty in typing on a real keyboard; or you are building a touchscreen-based web kiosk.
|
||||
|
@ -1,67 +0,0 @@
|
||||
Linux FAQs with Answers--How to access a NAT guest from host with VirtualBox
|
||||
================================================================================
|
||||
> **Question**: I have a guest VM running on VirtualBox, which uses NAT networking. So the guest VM is getting a private IP address (10.x.x.x) assigned by VirtualBox. If I want to SSH to the guest VM from the host machine, how can I do that?
|
||||
|
||||
VirtualBox supports several networking options for guest VMs, one of them being NAT networking. When NAT networking is enabled for a guest VM, VirtualBox automatically performs network address translation between the guest VM and host's network stack, so that you do not have to configure anything on the host machine and local network for the guest VM's networking to work. The implication of such NAT, however, is that the guest VM is not reachable or visible from external networks as well as from the local host itself. This is a problem if you want to access the guest VM from the host machine for some reason (e.g., SSH).
|
||||
|
||||
If you want to access a NAT guest from the host on VirtualBox, you can enable port forwarding for VirtualBox NAT, either from the GUI or from the command line. This tutorial demonstrates **how to SSH a NAT guest from the host** by enabling port forwarding for port 22. If you want to access HTTP of a NAT guest instead, replace port 22 with port 80.
|
||||
|
||||
### Configure VirtualBox Port Forwarding from the GUI ###
|
||||
|
||||
On VirtualBox, choose the guest VM you want to access, and open "Settings" window of the VM. Click on "Network" menu on the left, click on "Advanced" to show additional network adapter options.
|
||||
|
||||
![](https://farm8.staticflickr.com/7583/15797904856_2753dc785e_z.jpg)
|
||||
|
||||
Click on a button labeled "Port Forwarding."
|
||||
|
||||
![](https://farm8.staticflickr.com/7527/15636152708_cf2be7c7e8_z.jpg)
|
||||
|
||||
You will see a window where you can configure port forwarding rules. Click on "Add" icon in the upper right corner.
|
||||
|
||||
![](https://farm8.staticflickr.com/7489/15636391217_48a9954480_z.jpg)
|
||||
|
||||
Add a new port forwarding rule with the following detail.
|
||||
|
||||
- **Name**: SSH (any arbitrary unique name)
|
||||
- **Protocol**: TCP
|
||||
- **Host IP**: 127.0.0.1
|
||||
- **Host Port**: 2222 (any unused port higher than 1024)
|
||||
- **Guest IP**: IP address of the guest VM
|
||||
- **Guest Port**: 22 (SSH port)
|
||||
|
||||
![](https://farm6.staticflickr.com/5603/15202135853_02a07c3212_o.png)
|
||||
|
||||
Port forwarding configured for the guest VM will be enabled automatically when you power on the guest VM. For verification, check that port 2222 is opened by VirtualBox after you launch the guest VM:
|
||||
|
||||
$ sudo netstat -nap | grep 2222
|
||||
|
||||
![](https://farm8.staticflickr.com/7461/15819682411_6bb9707f8a_z.jpg)
|
||||
|
||||
Now that port forwarding is in place, you can SSH to the guest VM bs follows.
|
||||
|
||||
$ ssh -p 2222 <login>@127.0.0.1
|
||||
|
||||
An SSH login request sent to 127.0.0.1:2222 will automatically be translated into 10.0.2.15:22 by VirtualBox, allowing you to SSH to the guest VM.
|
||||
|
||||
### Configure VirtualBox Port Forwarding from the Command Line ###
|
||||
|
||||
VirtualBox comes with a command-line management interface called VBoxManage. Using this command-line tool, you can also set up port forwarding for your guest VM.
|
||||
|
||||
The following command creates a port forwarding rule for guest VM named "centos7" with IP address 10.0.2.15 and SSH port 22, mapped to local host at port 2222. The name of the rule ("SSH" in this example) must be unique.
|
||||
|
||||
$ VBoxManage modifyvm "centos7" --natpf1 "SSH,tcp,127.0.0.1,2222,10.0.2.15,22"
|
||||
|
||||
Once the rule is created, you can verify that by using the command below.
|
||||
|
||||
$ VBoxManage showvminfo "centos7" | grep NIC
|
||||
|
||||
![](https://farm8.staticflickr.com/7559/15636458427_7a0959900c_z.jpg)
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: http://ask.xmodulo.com/access-nat-guest-from-host-virtualbox.html
|
||||
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出
|
@ -1,3 +1,5 @@
|
||||
[felixonmars translating...]
|
||||
|
||||
How to install Docker on CentOS 7
|
||||
================================================================================
|
||||
Docker is an open-source tool that makes creating & managing **Linux containers(LXC)** easy. Containers are like lightweight VMs which can be started & stopped in milliseconds. Dockers help the system admin & coders to develop their application in a container and can further scale up to 1000 of nodes.
|
||||
@ -67,9 +69,9 @@ We can also search Containers based on fedora & ubuntu OS.
|
||||
via: http://www.linuxtechi.com/install-docker-on-centos-7/
|
||||
|
||||
作者:[Pradeep Kumar][a]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
译者:[felixonmars](https://github.com/felixonmars)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出
|
||||
|
||||
[a]:http://www.linuxtechi.com/author/pradeep/
|
||||
[a]:http://www.linuxtechi.com/author/pradeep/
|
||||
|
76
sources/tech/20141127 Quick systemd-nspawn guide.md
Normal file
76
sources/tech/20141127 Quick systemd-nspawn guide.md
Normal file
@ -0,0 +1,76 @@
|
||||
Quick systemd-nspawn guide
|
||||
================================================================================
|
||||
I switched to using systemd-nspawn in place of chroot and wanted to give a quick guide to using it. The short version is that I’d strongly recommend that anybody running systemd that uses chroot switch over - there really are no downsides as long as your kernel is properly configured.
|
||||
|
||||
Chroot should be no stranger to anybody who works on distros, and I suspect that the majority of Gentoo users have need for it from time to time.
|
||||
|
||||
### The Challenges of chroot ###
|
||||
|
||||
For most interactive uses it isn’t sufficient to just run chroot. Usually you need to mount /proc, /sys, and bind mount /dev so that you don’t have issues like missing ptys, etc. If you use tmpfs you might also want to mount the new tmp, var/tmp as tmpfs. Then you might want to make other bind mounts into the chroot. None of this is particularly difficult, but you usually end up writing a small script to manage it.
|
||||
|
||||
Now, I routinely do full backups, and usually that involves excluding stuff like tmp dirs, and anything resembling a bind mount. When I set up a new chroot that means updating my backup config, which I usually forget to do since most of the time the chroot mounts aren’t running anyway. Then when I do leave it mounted overnight I end up with backups consuming lots of extra space (bind mounts of large trees).
|
||||
|
||||
Finally, systemd now by default handles bind mounts a little differently when they contain other mount points (such as when using -rbind). Apparently unmounting something in the bind mount will cause systemd to unmount the corresponding directory on the other side of the bind. Imagine my surprise when I unmounted my chroot bind to /dev and discovered /dev/pts and /dev/shm no longer mounted on the host. It looks like there are ways to change that, but this isn’t the point of my post (it just spurred me to find another way).
|
||||
|
||||
### Systemd-nspawn’s Advantages ###
|
||||
|
||||
Systemd-nspawn is a tool that launches a container, and it can operate just like chroot in its simplest form. By default it automatically sets up most of the overhead like /dev, /tmp, etc. With a few options it can also set up other bind mounts as well. When the container exits all the mounts are cleaned up.
|
||||
|
||||
From the outside of the container nothing appears different when the container is running. In fact, you could spawn 5 different systemd-nspawn container instances from the same chroot and they wouldn’t have any interaction except via the filesystem (and that excludes /dev, /tmp, and so on - only changes in /usr, /etc will propagate across). Your backup won’t see the bind mounts, or tmpfs, or anything else mounted within the container.
|
||||
|
||||
The container also has all those other nifty container benefits like containment - a killall inside the container won’t touch anything outside, and so on. The security isn’t airtight - the intent is to prevent accidental mistakes.
|
||||
|
||||
Then, if you use a compatible sysvinit (which includes systemd, and I think recent versions of openrc), you can actually boot the container, which drops you to a getty inside. That means you can use fstab to do additional mounts inside the container, run daemons, and so on. You get almost all the benefits of virtualization for the cost of a chroot (no need to build a kernel, and so on). It is a bit odd to be running systemctl poweroff inside what looks just like a chroot, but it works.
|
||||
|
||||
Note that unless you do a bit more setup you will share the same network interface with the host, so no running sshd on the container if you have it on the host, etc. I won’t get into this but it shouldn’t be hard to run a separate network namespace and bind the interfaces so that the new instance can run dhcp.
|
||||
|
||||
### How to do it ###
|
||||
|
||||
So, getting it actually working will likely be the shortest bit in this post.
|
||||
|
||||
You need support for namespaces and multiple devpts instances in your kernel:
|
||||
|
||||
CONFIG_UTS_NS=y
|
||||
CONFIG_IPC_NS=y
|
||||
CONFIG_USER_NS=y
|
||||
CONFIG_PID_NS=y
|
||||
CONFIG_NET_NS=y
|
||||
CONFIG_DEVPTS_MULTIPLE_INSTANCES=y
|
||||
|
||||
From there launching a namespace just like a chroot is really simple:
|
||||
|
||||
systemd-nspawn -D .
|
||||
|
||||
That’s it - you can exit from it just like a chroot. From inside you can run mount and see that it has taken care of /dev and /tmp for you. The “.” is the path to the chroot, which I assume is the current directory. With nothing further it runs bash inside.
|
||||
|
||||
If you want to add some bind mounts it is easy:
|
||||
|
||||
systemd-nspawn -D . --bind /usr/portage
|
||||
|
||||
Now your /usr/portage is bound to your host, so no need to sync/etc. If you want to bind to a different destination add a “:dest” after the source, relative to the root of the chroot (so --bind foo is the same as --bind foo:foo).
|
||||
|
||||
If the container has a functional init that can handle being run inside, you can add a -b to boot it:
|
||||
|
||||
systemd-nspawn -D . --bind /usr/portage -b
|
||||
|
||||
Watch the init do its job. Shut down the container to exit.
|
||||
|
||||
Now, if that container is running systemd you can direct its journal to the host journal with -h:
|
||||
|
||||
systemd-nspawn -D . --bind /usr/portage -j -b
|
||||
|
||||
Now, nspawn registers the container so that it shows up in machinectl. That makes it easy to launch a new getty on it, or ssh to it (if it is running ssh - see my note above about network namespaces), or power it off from the host.
|
||||
|
||||
That’s it. If you’re running systemd I’d suggest ditching chroot almost entirely in favor of nspawn.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: http://rich0gentoo.wordpress.com/2014/07/14/quick-systemd-nspawn-guide/
|
||||
|
||||
作者:[rich0][a]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出
|
||||
|
||||
[a]:http://rich0gentoo.wordpress.com/
|
@ -1,51 +1,51 @@
|
||||
15 ‘pwd’ (Print Working Directory) Command Examples in Linux
|
||||
15条Linux下的‘pwd’命令(打印工作目录)示例
|
||||
================================================================================
|
||||
For those working with Linux command Line, command ‘**pwd**‘ is very helpful, which tells where you are – in which directory, starting from the root (**/**). Specially for Linux newbies, who may get lost amidst of directories in command Line Interface while navigation, command ‘**pwd**‘ comes to rescue.
|
||||
对于那些使用Linux命令行的人来说,‘**pwd**‘命令是非常有用的,它告诉你你现在在那个目录,从根目录(**/**)开始。特别对于或许会在目录的切换间容易糊涂的Linux新手而言,‘**pwd**‘ 可以拯救他们。
|
||||
|
||||
![15 pwd Command Examples](http://www.tecmint.com/wp-content/uploads/2014/11/pwd-command.png)
|
||||
|
||||
15 pwd Command Examples
|
||||
15 pwd 命令示例
|
||||
|
||||
### What is pwd? ###
|
||||
### 什么是pwd? ###
|
||||
|
||||
‘**pwd**‘ stands for ‘**Print Working Directory**‘. As the name states, command ‘**pwd**‘ prints the current working directory or simply the directory user is, at present. It prints the current directory name with the complete path starting from root (**/**). This command is built in shell command and is available on most of the shell – bash, Bourne shell, ksh,zsh, etc.
|
||||
‘**pwd**‘ 代表的是‘**Print Working Directory**’(打印当前目录)。如它的名字那样,‘**pwd**’会打印出当前工作目录或仅是目录用户。它会打印出以root (**/**)为起始的完整目录名。这条命令是一条shell内建命令,并且在大多数shell中都可以使用,如bash、Bourne shell,ksh、zsh等等。
|
||||
|
||||
#### Basic syntax of pwd: ####
|
||||
#### pwd的基本语法: ####
|
||||
|
||||
# pwd [OPTION]
|
||||
|
||||
#### Options used with pwd ####
|
||||
#### pwd的选项 ####
|
||||
|
||||
<table border="0" cellspacing="0">
|
||||
<colgroup width="126"></colgroup>
|
||||
<colgroup width="450"></colgroup>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td height="21" align="LEFT" style="border: 1px solid #000000;"><b><span style="font-size: small;"> Options</span></b></td>
|
||||
<td align="LEFT" style="border: 1px solid #000000;"><b><span style="font-size: small;"> Description</span></b></td>
|
||||
<td height="21" align="LEFT" style="border: 1px solid #000000;"><b><span style="font-size: small;"> 选项</span></b></td>
|
||||
<td align="LEFT" style="border: 1px solid #000000;"><b><span style="font-size: small;"> 描述</span></b></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td height="19" align="LEFT" style="border: 1px solid #000000;"><span style="font-family: Liberation Serif,Times New Roman; font-size: small;"> -L (logical)</span></td>
|
||||
<td align="LEFT" style="border: 1px solid #000000;"><span style="font-family: Liberation Serif,Times New Roman; font-size: small;"> Use PWD from environment, even if it contains symbolic links</span></td>
|
||||
<td align="LEFT" style="border: 1px solid #000000;"><span style="font-family: Liberation Serif,Times New Roman; font-size: small;"> 使用环境中的路径,即使包含了符号链接</span></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td height="19" align="LEFT" style="border: 1px solid #000000;"><span style="font-family: Liberation Serif,Times New Roman; font-size: small;"> -P (physical)</span></td>
|
||||
<td align="LEFT" style="border: 1px solid #000000;"><span style="font-family: Liberation Serif,Times New Roman; font-size: small;"> Avoid all symbolic links</span></td>
|
||||
<td align="LEFT" style="border: 1px solid #000000;"><span style="font-family: Liberation Serif,Times New Roman; font-size: small;"> 避免所有的符号链接</span></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td height="19" align="LEFT" style="border: 1px solid #000000;"><span style="font-family: Liberation Serif,Times New Roman; font-size: small;"> –help </span></td>
|
||||
<td align="LEFT" style="border: 1px solid #000000;"><span style="font-family: Liberation Serif,Times New Roman; font-size: small;"> Display this help and exit</span></td>
|
||||
<td align="LEFT" style="border: 1px solid #000000;"><span style="font-family: Liberation Serif,Times New Roman; font-size: small;"> 显示帮助并退出</span></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td height="19" align="LEFT" style="border: 1px solid #000000;"><span style="font-family: Liberation Serif,Times New Roman; font-size: small;"> –version</span></td>
|
||||
<td align="LEFT" style="border: 1px solid #000000;"><span style="font-family: Liberation Serif,Times New Roman; font-size: small;"> Output version information and exit</span></td>
|
||||
<td align="LEFT" style="border: 1px solid #000000;"><span style="font-family: Liberation Serif,Times New Roman; font-size: small;"> 输出版本信息并退出</span></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
If both ‘**-L**‘ and ‘**-P**‘ options are used, option ‘**L**‘ is taken into priority. If no option is specified at the prompt, pwd will avoid all symlinks, i.e., take option ‘**-P**‘ into account.
|
||||
如果同时使用了‘**-L**‘和‘**-P**‘,‘**-L**‘会有更高的优先级。如果没有指定参数,pwd会避开所有的软链接,也就是说会使用‘**-P**‘参数。
|
||||
|
||||
Exit status of command pwd:
|
||||
pwd的退出状态:
|
||||
|
||||
<table border="0" cellspacing="0">
|
||||
<colgroup width="128"></colgroup>
|
||||
@ -53,18 +53,18 @@ Exit status of command pwd:
|
||||
<tbody>
|
||||
<tr>
|
||||
<td height="19" align="CENTER" style="border: 1px solid #000000;"><span style="font-size: small;">0</span></td>
|
||||
<td align="CENTER" style="border: 1px solid #000000;"><span style="font-size: small;">Success</span></td>
|
||||
<td align="CENTER" style="border: 1px solid #000000;"><span style="font-size: small;">成功</span></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td height="19" align="CENTER" style="border: 1px solid #000000;"><span style="font-size: small;">Non-zero</span></td>
|
||||
<td align="CENTER" style="border: 1px solid #000000;"><span style="font-size: small;">Failure</span></td>
|
||||
<td align="CENTER" style="border: 1px solid #000000;"><span style="font-size: small;">失败</span></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
This article aims at providing you a deep insight of Linux command ‘**pwd**‘ with practical examples.
|
||||
本篇的目的是采用例子让你对‘**pwd**‘有更深入的领悟。
|
||||
|
||||
**1.** Print your current working directory.
|
||||
**1.** 打印放钱工作目录.
|
||||
|
||||
avi@tecmint:~$ /bin/pwd
|
||||
|
||||
@ -72,20 +72,20 @@ This article aims at providing you a deep insight of Linux command ‘**pwd**‘
|
||||
|
||||
![Print Working Directory](http://www.tecmint.com/wp-content/uploads/2014/11/pwd.gif)
|
||||
|
||||
Print Working Directory
|
||||
打印工作目录
|
||||
|
||||
**2.** Create a symbolic link of a folder (say **/var/www/html** into your home directory as **htm**). Move to the newly created directory and print working directory with symbolic links and without symbolic links.
|
||||
**2.** 为文件夹创建一个符号链接(比如说在home目录下创建一个**htm**链接指向**/var/www/html**)。进入新创建的目录并打印出含有以及不含符号链接的目录。
|
||||
|
||||
Create a symbolic link of folder /var/www/html as htm in your home directory and move to it.
|
||||
在home目录下创建一个htm链接指向/var/www/html,并进入。
|
||||
|
||||
avi@tecmint:~$ ln -s /var/www/html/ htm
|
||||
avi@tecmint:~$ cd htm
|
||||
|
||||
![Create Symbolic Link](http://www.tecmint.com/wp-content/uploads/2014/11/Create-Symbolic-Link.gif)
|
||||
|
||||
Create Symbolic Link
|
||||
创建符号链接
|
||||
|
||||
**3.** Print working directory from environment even if it contains symlinks.
|
||||
**3.** 从当前环境中答应目录即使它含有符号链接。
|
||||
|
||||
avi@tecmint:~$ /bin/pwd -L
|
||||
|
||||
@ -93,9 +93,9 @@ Create Symbolic Link
|
||||
|
||||
![Print Current Working Directory](http://www.tecmint.com/wp-content/uploads/2014/11/Print-Working-Directory.gif)
|
||||
|
||||
Print Current Working Directory
|
||||
打印工作目录
|
||||
|
||||
**4.** Print actual physical current working directory by resolving all symbolic links.
|
||||
**4.** 解析符号链接并打印出物理目录。
|
||||
|
||||
avi@tecmint:~$ /bin/pwd -P
|
||||
|
||||
@ -103,9 +103,9 @@ Print Current Working Directory
|
||||
|
||||
![Print Physical Working Directory](http://www.tecmint.com/wp-content/uploads/2014/11/Print-Physical-Working-Directory.gif)
|
||||
|
||||
Print Physical Working Directory
|
||||
打印物理工作目录
|
||||
|
||||
**5.** Check if the output of command “**pwd**” and “**pwd -P**” are same or not i.e., if no options are given at run-time does “**pwd**” takes option **-P** into account or not, automatically.
|
||||
**5.** 查看一下“**pwd**”和“**pwd -P**”的输出是否一致,也就是说,如果没有跟上选项,“**pwd**”时候会自动采用**-P**选项。
|
||||
|
||||
avi@tecmint:~$ /bin/pwd
|
||||
|
||||
@ -113,11 +113,11 @@ Print Physical Working Directory
|
||||
|
||||
![Check pwd Output](http://www.tecmint.com/wp-content/uploads/2014/11/Check-pwd-Output.gif)
|
||||
|
||||
Check pwd Output
|
||||
检查pwd输出
|
||||
|
||||
**Result:** It’s clear from the above output of example 4 and 5 (both result are same) thus, when no options are specified with command “**pwd**”, it automatically takes option “**-P**” into account.
|
||||
**结论:** 上面例子4和5的输出很明显(结果相同),当你“**pwd**”后面不带参数时,pwd会使用“**-P**”选项。
|
||||
|
||||
**6.** Print version of your ‘pwd’ command.
|
||||
**6.** 打印pwd命令的版本。
|
||||
|
||||
avi@tecmint:~$ /bin/pwd --version
|
||||
|
||||
@ -131,15 +131,15 @@ Check pwd Output
|
||||
|
||||
![Check pwd Version](http://www.tecmint.com/wp-content/uploads/2014/11/Check-pwd-Version.gif)
|
||||
|
||||
Check pwd Version
|
||||
检查pwd命令版本
|
||||
|
||||
**Note:** A ‘pwd’ command is often used without options and never used with arguments.
|
||||
**注意:** ‘pwd’ 通常不带选项运行,且没有任何参数
|
||||
|
||||
**Important:** You might have noticed that we are executing the above command as “**/bin/pwd**” and not “**pwd**”.
|
||||
**重要:** 你可能注意到我们刚才运行的都是 “**/bin/pwd**” 而不是 “**pwd**”。
|
||||
|
||||
So what’s the difference? Well “**pwd**” alone means shell built-in pwd. Your shell may have different version of pwd. Please refer manual. When we are using **/bin/pwd**, we are calling the binary version of that command. Both the shell and the binary version of command Prints Current Working Directory, though the binary version have more options.
|
||||
这有什么区别呢?直接使用“**pwd**”意味着使用shell内置的pwd。你的shell可能有不同版本的pwd。具体请参考手册。当你使用的是**/bin/pwd**时,我们调用的是二进制版本的命令。虽然二进制的版本有更多的选项,但是它们两者都能打印当前的目录。
|
||||
|
||||
**7.** Print all the locations containing executable named pwd.
|
||||
**7.** 打印所有含有可执行pwd的路径
|
||||
|
||||
avi@tecmint:~$ type -a pwd
|
||||
|
||||
@ -148,9 +148,9 @@ So what’s the difference? Well “**pwd**” alone means shell built-in pwd. Y
|
||||
|
||||
![Print Executable Locations](http://www.tecmint.com/wp-content/uploads/2014/11/Print-Executable-Locations.gif)
|
||||
|
||||
Print Executable Locations
|
||||
打印可执行文件路径
|
||||
|
||||
**8.** Store the value of “**pwd**” command in variable (say **a**), and print its value from the variable (important for shell scripting perspective).
|
||||
**8.** 存储“**pwd**”命令的值到变量中(比如说:**a** ),并从中打印i变量的值(对于观察shell脚本很重要)。
|
||||
|
||||
avi@tecmint:~$ a=$(pwd)
|
||||
avi@tecmint:~$ echo "Current working directory is : $a"
|
||||
@ -159,11 +159,11 @@ Print Executable Locations
|
||||
|
||||
![Store Pwd Value in Variable](http://www.tecmint.com/wp-content/uploads/2014/11/Store-Pwd-Value-in-Variable.gif)
|
||||
|
||||
Store Pwd Value in Variable
|
||||
存储pwd的值到变量中。
|
||||
|
||||
Alternatively, we can use **printf**, in the above example.
|
||||
下面的例子中也可以用**printf**来替代。
|
||||
|
||||
**9.** Change current working directory to anything (say **/home**) and display it in command line prompt. Execute a command (say ‘**ls**‘) to verify is everything is **OK**.
|
||||
**9.** 将工作路径切换到其他地方(比如说 **/home**),并在命令行中显示。通过执行命令(比如说 ‘**ls**‘)来验证一切**OK**。
|
||||
|
||||
avi@tecmint:~$ cd /home
|
||||
avi@tecmint:~$ PS1='$pwd> ' [Notice single quotes in the example]
|
||||
@ -171,14 +171,14 @@ Alternatively, we can use **printf**, in the above example.
|
||||
|
||||
![Change Current Working Directory](http://www.tecmint.com/wp-content/uploads/2014/11/Change-Current-Working-Directory.gif)
|
||||
|
||||
Change Current Working Directory
|
||||
改变当前工作路径
|
||||
|
||||
**10.** Set multi-line command line prompt (say something like below).
|
||||
**10.** 设置多行显示 (就像下面这样),
|
||||
|
||||
/home
|
||||
123#Hello#!
|
||||
|
||||
And then execute a command (say **ls**) to check is everything is **OK**.
|
||||
接着执行命令(比如说 **ls**)来检验一切**OK**。
|
||||
|
||||
avi@tecmint:~$ PS1='
|
||||
> $PWD
|
||||
@ -190,9 +190,9 @@ And then execute a command (say **ls**) to check is everything is **OK**.
|
||||
|
||||
![Set Multi Commandline Prompt](http://www.tecmint.com/wp-content/uploads/2014/11/Set-Multi-Commandline-Prompt.gif)
|
||||
|
||||
Set Multi Commandline Prompt
|
||||
设置多行显示
|
||||
|
||||
**11.** Check the current working directory and previous working directory in one GO!
|
||||
**11.** 一下子检查当前工作路径以及先前的工作路径。
|
||||
|
||||
avi@tecmint:~$ echo “$PWD $OLDPWD”
|
||||
|
||||
@ -201,28 +201,29 @@ Set Multi Commandline Prompt
|
||||
![Check Present Previous Working Directory](http://www.tecmint.com/wp-content/uploads/2014/11/Check-Present-Previous-Working-Directory.gif)
|
||||
|
||||
Check Present Previous Working Directory
|
||||
检查当前工作路径
|
||||
|
||||
**12.** What is the absolute path (starting from **/**) of the pwd binary file.
|
||||
**12.** pwd文件的绝对路径(以**/**开始)。
|
||||
|
||||
/bin/pwd
|
||||
|
||||
**13.** What is the absolute path (starting from **/**) of the pwd source file.
|
||||
**13.** pwd源文件文件的绝对路径(以**/**开始)。
|
||||
|
||||
/usr/include/pwd.h
|
||||
|
||||
**14.** Print the absolute path (starting from **/**) of the pwd manual pages file.
|
||||
**13.** 打印pwd手册的绝对路径(以**/**开始)。
|
||||
|
||||
/usr/share/man/man1/pwd.1.gz
|
||||
|
||||
**15.** Write a shell script analyses current directory (say **tecmint**) in your home directory. If you are under directory **tecmint** it output “**Well! You are in tecmint directory**” and then print “**Good Bye**” else create a directory **tecmint** under your home directory and ask you to cd to it.
|
||||
**15.** 写一个shell脚本分析home目录下的一个目录(比如**tecmint**)。如果当前目录是**tecmint**就输出“**Well! You are in tecmint directory**”接着输出“**Good Bye**”,不然就在**tecmint**下面创建一个目录并提示你cd进入它。
|
||||
|
||||
Let’s first create a ‘tecmint’ directory, under it create a following shell script file with name ‘pwd.sh’.
|
||||
让我们首先创建一个‘tecmint’目录,在下面创建一个名为‘pwd.sh’的脚本文件。
|
||||
|
||||
avi@tecmint:~$ mkdir tecmint
|
||||
avi@tecmint:~$ cd tecmint
|
||||
avi@tecmint:~$ nano pwd.sh
|
||||
|
||||
Next, add the following script to the pwd.sh file.
|
||||
接下来在pwd.sh中加入下面的脚本。
|
||||
|
||||
#!/bin/bash
|
||||
|
||||
@ -240,7 +241,7 @@ Next, add the following script to the pwd.sh file.
|
||||
}
|
||||
fi
|
||||
|
||||
Give execute permission and run it.
|
||||
给予他执行权限并运行。
|
||||
|
||||
avi@tecmint:~$ chmod 755 pwd.sh
|
||||
avi@tecmint:~$ ./pwd.sh
|
||||
@ -248,16 +249,16 @@ Give execute permission and run it.
|
||||
Well you are in tecmint directory
|
||||
Good Bye
|
||||
|
||||
#### Conclusion ####
|
||||
#### 总结 ####
|
||||
|
||||
**pwd** is one of the simplest yet most popular and most widely used command. A good command over pwd is basic to use Linux terminal. That’s all for now. I’ll be here again with another interesting article soon, till then stay tuned and connected to Tecmint.
|
||||
**pwd**是一个最简单且会广泛用到的命令。掌握好pwd是使用Linux终端的基础。就是这些了。我很快会再带来另外有趣的注意,请不要走开继续关注Tecmint。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: http://www.tecmint.com/pwd-command-examples/
|
||||
|
||||
作者:[Avishek Kumar][a]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
译者:[geekpi](https://github.com/geekpi)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出
|
@ -0,0 +1,67 @@
|
||||
Linux 有问必答 -- 如何从VirtualBox中从主机访问NAT客户机
|
||||
================================================================================
|
||||
> **提问**: 我有一台运行在VirtualBox上的使用NAT的虚拟机。因此虚拟机会被VirtualBox分配一个私有IP地址(10.x.x.x)。如果我想要从主机SSH到虚拟机中,我该怎么做?
|
||||
|
||||
VirtualBox对虚拟机支持几种不同的网络方式,其中一种是NAT网络。当虚拟机启用NAT后,VirtualBox会自动在虚拟机和主机之间进行网络翻译,因此你不于必在虚拟机和主机之间配置任何东西。这也意味着NAT中的虚拟机对于外部网络以及主机本身是不可见的。这会在你想要从主机访问虚拟机时会产生问题(比如SSH)。
|
||||
|
||||
如果你想从VirtualBox的NAT环境的虚拟机,你可以在GUI或者命令行下启用VirtualBox NAT的端口转发。本篇教程将会演示**如何通过启用22端口转发而从主机SSH连接到NAT环境的客户机**。如果你先想要从HTTP访问NAT的客户机,用80端口代替22端口即可。
|
||||
|
||||
### 通过GUI配置VirtualBox端口转发 ###
|
||||
|
||||
在VirtualBox中选择你想要访问的虚拟机,打开虚拟机的“设置”。点击左侧的“网络”菜单,点击网络适配选项的“高级”。
|
||||
|
||||
![](https://farm8.staticflickr.com/7583/15797904856_2753dc785e_z.jpg)
|
||||
|
||||
点击“端口转发”按钮
|
||||
|
||||
![](https://farm8.staticflickr.com/7527/15636152708_cf2be7c7e8_z.jpg)
|
||||
|
||||
你会看到一个配置端口转发规则的窗口。点击右上角的“添加”图标。
|
||||
|
||||
![](https://farm8.staticflickr.com/7489/15636391217_48a9954480_z.jpg)
|
||||
|
||||
就会看到像下面那样的转发规则。
|
||||
|
||||
- **Name**: SSH (可以是任意唯一名)
|
||||
- **Protocol**: TCP
|
||||
- **Host IP**: 127.0.0.1
|
||||
- **Host Port**: 2222 (任何大于1024未使用的端口)
|
||||
- **Guest IP**: 虚拟机IP
|
||||
- **Guest Port**: 22 (SSH 端口)
|
||||
|
||||
![](https://farm6.staticflickr.com/5603/15202135853_02a07c3212_o.png)
|
||||
|
||||
端口转发的规则会自动在你启动虚拟机的时候启用。为了验证。可以在你启用虚拟机后检查端口2222是否被VirtualBox开启了。
|
||||
|
||||
$ sudo netstat -nap | grep 2222
|
||||
|
||||
![](https://farm8.staticflickr.com/7461/15819682411_6bb9707f8a_z.jpg)
|
||||
|
||||
现在端口转发可以使用了,你可以用下面的命令SSH到虚拟机。
|
||||
|
||||
$ ssh -p 2222 <login>@127.0.0.1
|
||||
|
||||
发送到127.0.0.1:2222的登录请求会自动被VirtualBox翻译成10.0.2.15:22,这可以让你SSH到虚拟机中。
|
||||
|
||||
### 通过命令行配置VirtualBox端口转发 ###
|
||||
|
||||
VirtualBox有一个称为VBoxManage的命令行管理工具。使用命令行工具,你也可以为你的虚拟机设置端口转发。
|
||||
|
||||
下面的命令会为IP地址为10.0.2.15的虚拟机设置一个名字为"centos7"的端口转发规则,SSH的端口号为22,映射到本地主机的端口为2222。规则的名字(本例中是SSH)必须是唯一的。
|
||||
|
||||
$ VBoxManage modifyvm "centos7" --natpf1 "SSH,tcp,127.0.0.1,2222,10.0.2.15,22"
|
||||
|
||||
规则创建之后,你可以用下面的命令来验证。
|
||||
|
||||
$ VBoxManage showvminfo "centos7" | grep NIC
|
||||
|
||||
![](https://farm8.staticflickr.com/7559/15636458427_7a0959900c_z.jpg)
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: http://ask.xmodulo.com/access-nat-guest-from-host-virtualbox.html
|
||||
|
||||
译者:[geekpi](https://github.com/geekpi)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出
|
Loading…
Reference in New Issue
Block a user