Skip to Content
Linux Shell Scripting Cookbook - Third Edition
book

Linux Shell Scripting Cookbook - Third Edition

by Clif Flynt, Sarath Lakshman, Shantanu Tushar
May 2017
Beginner
552 pages
28h 47m
English
Packt Publishing
Content preview from Linux Shell Scripting Cookbook - Third Edition

How to do it...

iptables is present by default on all modern Linux distributions. It's easy to configure for common scenarios:

  1.  If don't want to contact a given site (for example, a known malware site), you can block traffic to that IP address:
        #iptables -A OUTPUT -d 8.8.8.8 -j DROP 

If you use PING 8.8.8.8 in another terminal, then by running the iptables command, you will see this:

        PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data. 
        64 bytes from 8.8.8.8: icmp_req=1 ttl=56 time=221 ms 
        64 bytes from 8.8.8.8: icmp_req=2 ttl=56 time=221 ms 
        ping: sendmsg: Operation not permitted 
        ping: sendmsg: Operation not permitted 

Here, the ping fails the third time because we used the iptables command to drop all traffic to 8.8.8.8.

  1. You can also block ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Mastering Linux Shell Scripting - Second Edition

Mastering Linux Shell Scripting - Second Edition

Mokhtar Ebrahim, Andrew Mallett

Publisher Resources

ISBN: 9781785881985