- Linux Administration Cookbook
- Adam K. Dean
- 172字
- 2021-07-02 14:24:19
Getting ready
On centos2, run the following command:
[vagrant@centos2 ~]$ python -m SimpleHTTPServer 8888
Serving HTTP on 0.0.0.0 port 8888 ...
You've just created a small, Python-based web server, listening on every address at port 8888.
You can confirm this by running a curl command from centos1:
[vagrant@centos1 ~]$ curl 192.168.33.11:8888
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"><html>
<title>Directory listing for /</title>
<body>
<h2>Directory listing for /</h2>
<hr>
<ul>
<li><a href=".bash_logout">.bash_logout</a>
<li><a href=".bash_profile">.bash_profile</a>
<li><a href=".bashrc">.bashrc</a>
<li><a href=".ssh/">.ssh/</a>
</ul>
<hr>
</body>
</html>
Note the listing of the home directory contents from centos2.
On centos2, you should see your connection (200 response):
[vagrant@centos2 ~]$ python -m SimpleHTTPServer 8888
Serving HTTP on 0.0.0.0 port 8888 ...
192.168.33.10 - - [09/Aug/2018 10:47:13] "GET / HTTP/1.1" 200 -
Python's built-in web server module is very handy for testing. I used it here because it's available out of the box in our installation, but I wouldn't use it in a production environment, as there are better (and faster) alternatives.
To confirm we've not yet got anything listening locally on port 9999, perform another curl command from centos1:
[vagrant@centos1 ~]$ curl 127.0.0.1:9999
curl: (7) Failed connect to 127.0.0.1:9999; Connection refused