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...

  1. Connect to the Internet. In this recipe, we are assuming that the primary wired network connection, eth0, is connected to the Internet. Change it according to your setup.
  2. Using your distro's network management tool, create a new ad hoc wireless connection with the following settings:
    • IP address: 10.99.66.55
  • Subnet mask: 255.255.0.0 (16)
  1. Use the following shell script to share the Internet connection:
        #!/bin/bash 
        #filename: netsharing.sh

        echo 1 > /proc/sys/net/ipv4/ip_forward 

        iptables -A FORWARD -i $1 -o $2 \
            -s 10.99.0.0/16 -m conntrack --ctstate NEW -j ACCEPT 

        iptables -A FORWARD -m conntrack --ctstate \
            ESTABLISHED,RELATED -j ACCEPT

        iptables -A POSTROUTING -t nat -j MASQUERADE

  1.  Run the script:
 ./netsharing.sh ...
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